If you can use node -set as an extension of your xslt 1.0 processor, you can try this.
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> <xsl:output method="xml" indent="yes" /> <xsl:variable name="date" select="'10-JAN-2013'" /> <xsl:variable name="month_data_tmp"> <month short="JAN" nr="01" /> </xsl:variable> <xsl:variable name="month_data" select="exsl:node-set($month_data_tmp)" /> <xsl:template name="format_date" > <xsl:param name ="date" /> <xsl:variable name ="day" select="substring-before($date, '-')" /> <xsl:variable name ="month_and_year" select="substring-after($date, '-')" /> <xsl:variable name ="year" select="substring-after($month_and_year, '-')" /> <xsl:variable name ="month" select="substring-before($month_and_year, '-')" /> <xsl:value-of select="$year"/> <xsl:value-of select="$month_data/month[@short=$month]/@nr"/> <xsl:value-of select="$day"/> </xsl:template> <xsl:template match="/" > <xsl:call-template name="format_date" > <xsl:with-param name ="date" select="$date"/> </xsl:call-template> </xsl:template>
The output will be:
20130110
Update doe to an additional question on the command:
You can call the template anywhere you used <xsl:value-of select="$date"/> before.
<result> <xsl:call-template name="format_date" > <xsl:with-param name ="date" select="$date"/> </xsl:call-template> </result>
Or you can assign the result to a new variable and use it.
<xsl:variable name="newdate"> <xsl:call-template name="format_date" > <xsl:with-param name ="date" select="$date"/> </xsl:call-template> </xsl:variable> <result> <xsl:value-of select="$newdate"/> </result>
source share