Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Variables and Parameters (12/14) >

Passing nodes as parameters

Parameters can be used in the same way as variables.

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/aaa">
                  <xxx>
                        <xsl:apply-templates  select="bbb"/>
                  </xxx>
                  <yyy>
                        <xsl:apply-templates  select="bbb">
                              <xsl:with-param  name="A"
                                          select="bbb/ccc"/>
                        </xsl:apply-templates>
                  </yyy>
            </xsl:template>

            <xsl:template  match="bbb">
                  <xsl:param  name="A"
                              select="/aaa/bbb/ccc[last()]"/>
                  <xsl:copy-of  select="$A"/>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb>
                  <ccc  r="1"/>
                  <ccc  r="2"/>
                  <ccc  r="3"/>
            </bbb>
      </aaa>
Output

      <xxx>
            <ccc  r="3"/>
      </xxx>
      <yyy>
            <ccc  r="1"/>
            <ccc  r="2"/>
            <ccc  r="3"/>
      </yyy>


Previous chapter: Named-Templates
Next chapter: Stylesheet Functions
Previous page: Default values of parameters
Next page: Difference between parameters and variables