Mega Code Archive

 
Categories / XML Tutorial / XSLT StyleSheet
 

Define variable and use it

File: Data.xml <x>    <input>7</input>    <input>27</input> </x> File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   version="1.0">   <xsl:output method="text" indent="yes" version="1.0" />   <xsl:template match="x">     <xsl:apply-templates select="y" />   </xsl:template>   <xsl:template match="y">     <xsl:param name="x" select="/x/input" />     <xsl:variable name="y" select="$x - 1" />     <xsl:variable name="z" select="." />     <xsl:value-of select="$x" />     <xsl:text> - 1 = </xsl:text>     <xsl:value-of select="$y" />     <xsl:text>&#013;</xsl:text>     <xsl:if test="$x > 1">       <xsl:apply-templates select="$z">         <xsl:with-param name="x" select="$x - 1" />       </xsl:apply-templates>     </xsl:if>   </xsl:template> </xsl:stylesheet>