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

Axes preceding and following

The "preceding::" axis of an element contains all elements which precedes the element in the document order and which are not its ancestors.

The "following::" axis of an element contains all elements which follows the element in the document order and which are not its descendants.

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>
                        <xsl:apply-templates  select="/aaa/ccc/ccc-b/preceding::*"/>
                  </xxx>
                  <yyy>
                        <xsl:apply-templates  select="/aaa/ccc/ccc-b/following::*"/>
                  </yyy>
            </xsl:template>

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

      </xsl:stylesheet>
XML

      <aaa>
            <bbb>
                  <bbb-a/>
                  <bbb-b/>
            </bbb>
            <ccc>
                  <ccc-a/>
                  <ccc-b>
                        <ccc-b-1/>
                        <ccc-b-2/>
                  </ccc-b>
                  <ccc-c/>
            </ccc>
            <ddd>
                  <ddd-a/>
                  <ddd-b/>
            </ddd>
      </aaa>
Output

      <xxx>
            <zzz  name="bbb"
                        position="1"/>
            <zzz  name="bbb-a"
                        position="2"/>
            <zzz  name="bbb-b"
                        position="3"/>
            <zzz  name="ccc-a"
                        position="4"/>
      </xxx>
      <yyy>
            <zzz  name="ccc-c"
                        position="1"/>
            <zzz  name="ddd"
                        position="2"/>
            <zzz  name="ddd-a"
                        position="3"/>
            <zzz  name="ddd-b"
                        position="4"/>
      </yyy>


Previous chapter: Sorting
Next chapter: Named-Templates
Previous page: Descendant and ancestor axes
Next page: Axes preceding-sibling and following-sibling

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