Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Implicit behaviour (8/10) >

Implicit passing of parameters

Implicit templates automatically pass parameters which they receive from the calling template with their xsl:apply-templates call.

There is no explicit template between bbb and ddd element in the first case and so the parameter is passed to the ddd template. In the second case there is an intervening eee template which does not pass parameters with its xsl:apply-templates call and so the second DDD is empty.

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">
                              <xsl:with-param  name="par"
                                          select="8"/>
                        </xsl:apply-templates>
                  </xxx>
            </xsl:template>

            <xsl:template  match="ddd">
                  <xsl:param  name="par"/>
                  <DDD>
                        <xsl:value-of  select="$par"/>
                  </DDD>
            </xsl:template>

            <xsl:template  match="eee">
                  <EEE>
                        <xsl:apply-templates/>
                  </EEE>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb>
                  <ccc>
                        <ddd/>
                  </ccc>
            </bbb>
            <bbb>
                  <eee>
                        <ddd/>
                  </eee>
            </bbb>
      </aaa>
Output

      <xxx>
            <DDD>8</DDD>
            <EEE>
                  <DDD/>
            </EEE>
      </xxx>


Previous chapter: Context
Next chapter: Arithmetics
Previous page: Implicit templates for text nodes
Next page: Priorities of implicit templates