
February 10th, 2004, 01:45 PM
|
 |
Java PHP Oracle Developer
|
|
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204
Time spent in forums: 15 m 26 sec
Reputation Power: 5
|
|
Let me know if you need any explaining.
Code:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- this variable must be a length of 1 -->
<xsl:variable name="DELIMETER_FILE_EXTENSION" select="'.'"/>
<xsl:template match="/">
<xsl:variable name="file" select="'this.is.a.file.txt'"/>
<!-- example: print out the file extension -->
<xsl:call-template name="getFileExtension">
<xsl:with-param name="file" select="$file"/>
</xsl:call-template>
<!-- example: store the file extension in a variable -->
<xsl:variable name="fileExtension">
<xsl:call-template name="getFileExtension">
<xsl:with-param name="file" select="$file"/>
</xsl:call-template>
</xsl:variable>
</xsl:template>
<xsl:template name="getFileExtension">
<xsl:param name="file"/>
<xsl:if test="contains($file, $DELIMETER_FILE_EXTENSION)">
<xsl:variable name="fileLength" select="string-length($file)"/>
<xsl:variable name="delemiterPosition">
<xsl:call-template name="getDelemiterPosition">
<xsl:with-param name="file" select="$file"/>
<xsl:with-param name="startSearchPosition"
select="$fileLength"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="substring($file,
$delemiterPosition + 1,
$fileLength - $delemiterPosition + 1)"/>
</xsl:if>
</xsl:template>
<xsl:template name="getDelemiterPosition">
<xsl:param name="file"/>
<xsl:param name="startSearchPosition"/>
<xsl:if test="$startSearchPosition > 0">
<xsl:choose>
<xsl:when test="substring($file, $startSearchPosition, 1) = $DELIMETER_FILE_EXTENSION">
<xsl:value-of select="$startSearchPosition"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="getDelemiterPosition">
<xsl:with-param name="file" select="$file"/>
<xsl:with-param name="startSearchPosition"
select="$startSearchPosition - 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Last edited by MattSidesinger : February 10th, 2004 at 01:49 PM.
|