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

Descendant-or-self and ancestor-or-self axes

The "descendant-or-self::" axis contains all descendants of a node and the node itself. Similarly, "ancestor-or-self::"Contains all ancestors of the node and the node itself.

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="/">
                  <xxx>
                        <i>
                              <xsl:apply-templates  select="aaa/descendant::*"/>
                        </i>
                        <ii>
                              <xsl:apply-templates  select="aaa/descendant-or-self::*"/>
                        </ii>
                  </xxx>
                  <yyy>
                        <i>
                              <xsl:apply-templates  select="aaa/bbb/ccc/ddd/ancestor::*"/>
                        </i>
                        <ii>
                              <xsl:apply-templates  select="aaa/bbb/ccc/ddd/ancestor-or-self::*"/>
                        </ii>
                  </yyy>
            </xsl:template>

            <xsl:template  match="*">
                  <iii  name="{name(.)}"
                              position="{position()}"/>
            </xsl:template>

      </xsl:stylesheet>
XML

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

      <xxx>
            <i>
                  <iii  name="bbb"
                              position="1"/>
                  <iii  name="ccc"
                              position="2"/>
                  <iii  name="ddd"
                              position="3"/>
            </i>
            <ii>
                  <iii  name="aaa"
                              position="1"/>
                  <iii  name="bbb"
                              position="2"/>
                  <iii  name="ccc"
                              position="3"/>
                  <iii  name="ddd"
                              position="4"/>
            </ii>
      </xxx>
      <yyy>
            <i>
                  <iii  name="aaa"
                              position="1"/>
                  <iii  name="bbb"
                              position="2"/>
                  <iii  name="ccc"
                              position="3"/>
            </i>
            <ii>
                  <iii  name="aaa"
                              position="1"/>
                  <iii  name="bbb"
                              position="2"/>
                  <iii  name="ccc"
                              position="3"/>
                  <iii  name="ddd"
                              position="4"/>
            </ii>
      </yyy>


Previous chapter: Sorting
Next chapter: Named-Templates
Previous page: Self axis
Next page: - - -

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