Previous | Next | Indexes
adultinternetusers > Tutorials > XSLT 2.0 Tutorial > Context (6/6) >

Template context via variable

If context is changed in the template (e.g. by usage of xsl:for-each element), the function current() returns the changed context, not the context of the containing template.

If the template context is needed it may be saved to a variable and then used.

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">
                  <xsl:apply-templates  select="bbb"/>
            </xsl:template>

            <xsl:template  match="bbb">
                  <xsl:variable  name="a"
                              select="."/>
                  <xsl:for-each  select="/aaa/ccc">
                        <iii>
                              <xsl:copy-of  select="."/>
                              <xsl:copy-of  select="current()"/>
                              <xsl:copy-of  select="$a"/>
                        </iii>
                  </xsl:for-each>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb>B1</bbb>
            <bbb>B2</bbb>
            <ccc>C1</ccc>
            <ccc>C2</ccc>
            <ccc>C3</ccc>
      </aaa>
Output

      <iii>
            <ccc>C1</ccc>
            <ccc>C1</ccc>
            <bbb>B1</bbb>
      </iii>
      <iii>
            <ccc>C2</ccc>
            <ccc>C2</ccc>
            <bbb>B1</bbb>
      </iii>
      <iii>
            <ccc>C3</ccc>
            <ccc>C3</ccc>
            <bbb>B1</bbb>
      </iii>
      <iii>
            <ccc>C1</ccc>
            <ccc>C1</ccc>
            <bbb>B2</bbb>
      </iii>
      <iii>
            <ccc>C2</ccc>
            <ccc>C2</ccc>
            <bbb>B2</bbb>
      </iii>
      <iii>
            <ccc>C3</ccc>
            <ccc>C3</ccc>
            <bbb>B2</bbb>
      </iii>


Previous chapter: Modes
Next chapter: Implicit behaviour
Previous page: Template context in XPath expressions - function current
Next page: - - -

Kevin Carr

Natural Skin Care European Soaps
Scented Body Care Shea Body Butter
city of stanton
search engine optimization orange county internetusers


Also, you will want to check out Stanton California so you can see what's up and they are part of Stanton City Hall as well.

You can also get Organic Skin Care products from Bliss Bath Body and you must check out their Natural Body Lotions and bath soaps

Now if you are looking for the best deals on surf clothing from Quiksilver and Roxy then you have to check these amazing deals here:

Hey, check out this Organic Skin Care European Soaps along with Natural Lavender Body Lotion and shea butter

This is the guy we need in government office. His name is Kevin Carr City Of Stanton Council Candidate and he is a great guy. and we can get surf t shirts surfing shirt and And you must check out this website swim suit swimming suit and swim trunks