Get File Extension
Get the extension of a filename
Description
Get the extension of a filename.
Usage example:
<xsl:call-template name="get-file-extension">
<xsl:with-param name="path" select="my-upload/filename" />
</xsl:call-template>
XSLT
View Raw
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Get the extension of a filename Usage example: <xsl:call-template name="get-file-extension"> <xsl:with-param name="path" select="my-upload/filename" /> </xsl:call-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="get-file-extension"> <xsl:with-param name="path" select="substring-after($path, '.')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$path"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>