Define variable and use it : variable « XSLT stylesheet « XML Tutorial






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>








5.68.variable
5.68.1.Define variable and use it
5.68.2.Fill position to a variable
5.68.3.Define and use variable
5.68.4.Variable scope
5.68.5.Variable assignment with choose statement
5.68.6.There is an important difference in variable value specification.
5.68.7.if a variable has some defined value
5.68.8.Variable without initialization
5.68.9.demonstrate different ways of setting xsl:variable
5.68.10.Use variable to hold a result tree