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

Template context in XPath expressions - function current()

The current() function returns the context item of the place where XPath expression was 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">
                  <xxx>
                        <yyy>
                              <xsl:value-of  select="name(.),@x,position()"
                                          separator=" - "/>
                        </yyy>
                        <zzz>
                              <z1>
                                    <xsl:value-of  select="@*"
                                                separator=" | "/>
                              </z1>
                              <z2>
                                    <xsl:value-of  select="*/@*"
                                                separator=" | "/>
                              </z2>
                              <z3>
                                    <xsl:value-of  select="*/current()/@*"
                                                separator=" | "/>
                              </z3>
                        </zzz>
                  </xxx>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb  x="000">B1</bbb>
            <bbb  x="111">B2</bbb>
            <bbb  x="222">
                  <ccc  y="555">C1</ccc>
                  <ccc  y="666">C2</ccc>
                  <ccc  y="777">C3</ccc>
            </bbb>
            <bbb  x="333">
                  <ccc  y="888">C5</ccc>
                  <ccc  y="999">C6</ccc>
            </bbb>
      </aaa>
Output

      <xxx>
            <yyy>bbb - 000 - 1</yyy>
            <zzz>
                  <z1>000</z1>
                  <z2/>
                  <z3/>
            </zzz>
      </xxx>
      <xxx>
            <yyy>bbb - 111 - 2</yyy>
            <zzz>
                  <z1>111</z1>
                  <z2/>
                  <z3/>
            </zzz>
      </xxx>
      <xxx>
            <yyy>bbb - 222 - 3</yyy>
            <zzz>
                  <z1>222</z1>
                  <z2>555 | 666 | 777</z2>
                  <z3>222</z3>
            </zzz>
      </xxx>
      <xxx>
            <yyy>bbb - 333 - 4</yyy>
            <zzz>
                  <z1>333</z1>
                  <z2>888 | 999</z2>
                  <z3>333</z3>
            </zzz>
      </xxx>


Previous chapter: Modes
Next chapter: Implicit behaviour
Previous page: Context item in XPath expressions
Next page: Template context via variable

Kevin Carr in Stanton

Natural Skin Care and European Soaps
Kevin Carr
Mayor Dave Shawver Stanton
Internetusers


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

and we can get surf t shirts surfing shirt and And you must check out this website swim suit swimming suit and swim trunks