|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Determine file extension of path stored in variabl
> I am not sure what should be done in the case where
> the path doesn't contain a '.' (or how to trap that
>condition)
I suggest the following XSL to trap this condition..
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:variable name="lcpath"
select="'/images/dir.path/file.png'" />
<xsl:template match="/">
<xsl:variable name="ext">
<xsl:call-template name="get-file-extension">
<xsl:with-param name="path" select="$lcpath" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$ext" />
</xsl:template>
<xsl:template name="get-file-extension">
<xsl:param name="path" />
<xsl:choose>
<xsl:when test="contains( $path, '/' )">
<xsl:call-template name="get-file-extension">
<xsl:with-param name="path"
select="substring-after($path, '/')" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains( $path, '.' )">
<xsl:call-template name="TEMP">
<xsl:with-param name="x"
select="substring-after($path, '.')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:text>No extension</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="TEMP">
<xsl:param name="x" />
<xsl:choose>
<xsl:when test="contains($x, '.')">
<xsl:call-template name="TEMP">
<xsl:with-param name="x"
select="substring-after($x, '.')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$x" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
With the above XSL, if path contains a . after the
last / character, the stylesheet outputs just as
before (it prints the extension name). But if the path
is something like - <xsl:variable name="lcpath"
select="'/images/dir.path/filepng'" /> , the XSL
prints "No extension"..
You can choose to write <xsl:text></xsl:text> instead
of <xsl:text>No extension</xsl:text> .. (to output
nothing, if there is no extension)..
>Is there a better way to code the two
> xsl:when blocks below that basically do the same
> thing but with different characters?
The way you have modified the code, looks fine to me!
Regards,
Mukul
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








