Previous | Next | Indexes
adultinternetusers > Tutorials > XSLT 2.0 Tutorial > Axes (7/8) >

Self axis

The "self::" axis of an node always contains only one item, the context node itself. Nevertheless, this axis may be very useful when namespaces are involved. Study carefully the example. If the comparison was based on name() function then the processing would be difficult as namespace prefixes would cause severe problems.

XSLT

      <xsl:stylesheet
                  xmlns:c="111"
                  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="/">
                  <xxx>
                        <xsl:apply-templates  select="/*"/>
                  </xxx>
                  <yyy>
                        <xsl:apply-templates  select="/*/*"/>
                  </yyy>
            </xsl:template>

            <xsl:template  match="*">
                  <zzz  name="{name()}"
                              position="{position()}">
                        <xsl:choose>
                              <xsl:when  test="self::c:aaa">
                                    <MATCH/>
                              </xsl:when>
                              <xsl:otherwise>
                                    <NOTHING/>
                              </xsl:otherwise>
                        </xsl:choose>
                  </zzz>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa
                  xmlns:a="111"
                  xmlns:b="111">
            <a:aaa/>
            <b:aaa/>
            <a:aaa
                        xmlns:a="222"/>
      </aaa>
Output

      <xxx
                  xmlns:c="111">
            <zzz  name="aaa"
                        position="1">
                  <NOTHING/>
            </zzz>
      </xxx>
      <yyy
                  xmlns:c="111">
            <zzz  name="a:aaa"
                        position="1">
                  <MATCH/>
            </zzz>
            <zzz  name="b:aaa"
                        position="2">
                  <MATCH/>
            </zzz>
            <zzz  name="a:aaa"
                        position="3">
                  <NOTHING/>
            </zzz>
      </yyy>


Previous chapter: Sorting
Next chapter: Named-Templates
Previous page: Attribute axis
Next page: Descendant-or-self and ancestor-or-self axes

Kevin Carr in Stanton

Natural Skin Care and European Soaps
TickTalk 5
city of 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