to the main page about the tutorial  THE XML REVOLUTION  -  TECHNOLOGIES FOR THE FUTURE WEB back up next

Variables and parameters

- for reusing results of computations and parameterizing templates and whole stylesheets Declaration: - similarly for xsl:param parameter declarations (where the specified values act as defaults).

Use:

Example 1:
<xsl:template match="foo">

  <xsl:variable name="X" select="42"/>
  <xsl:variable name="Y">
    <sometag><xsl:value-of select="@bar"/></sometag>
  </xsl:variable>

  <first>
    <xsl:value-of select="$X"/>
    <xsl:copy-of select="$Y"/>
  </first>
  <second>
    <xsl:value-of select="$X"/>
    <xsl:copy-of select="$Y"/>
  </second>

</xsl:template>

Example 2:
  ...
  <xsl:apply-templates select="item">
    <xsl:with-param name="COLOR" select="'blue'"/>
  </xsl:apply-templates>
  ...

<xsl:template match="item">
  <xsl:param name="COLOR" select="'black'"/>
  <font color="{$COLOR}">
    <xsl:apply-templates/>
  </font>
</xsl:template>

back COPYRIGHT © 2000-2003 ANDERS MØLLER & MICHAEL I. SCHWARTZBACH next