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

Recursive addition of attributes

In this example attributes are added to all elements. xsl:copy copies the matching element node from the source document (without attribute and descendant nodes) and xsl:copy-of adds to these elements already existing attributes. The values of new attributes are set to the value of position() function and to the number of elements on "preceding-sibling::" axis. The values of these attributes always differ by one. If you understand the process of templates matching you know that it is not a coincidence.

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="*">
                  <xsl:copy>
                        <xsl:copy-of  select="@*"/>
                        <xsl:attribute  name="a"
                                    select="position()"/>
                        <xsl:attribute  name="z"
                                    select="count(preceding-sibling::*)"/>
                        <xsl:apply-templates  select="*"/>
                  </xsl:copy>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb  r="11"/>
            <ccc>
                  <ddd  r="7"
                              s="12"/>
                  <eee  r="3"
                              s="27"/>
            </ccc>
      </aaa>
Output

      <aaa  a="1"
                  z="0">
            <bbb  r="11"
                        a="1"
                        z="0"/>
            <ccc  a="2"
                        z="1">
                  <ddd  r="7"
                              s="12"
                              a="1"
                              z="0"/>
                  <eee  r="3"
                              s="27"
                              a="2"
                              z="1"/>
            </ccc>
      </aaa>


Previous chapter: Keys
Next chapter: Date and Time
Previous page: Recursive renaming of elements
Next page: Recursive change of the value of attributes

Kevin Carr
North Orange County Title Insurance Company Kevin Mount
Natural Skin Care European Soaps
Scented Body Care Shea Body Butter
city of stanton
search engine optimization orange county internetusers


Quiksilver Board Shorts
Roxy Board Shorts
Volcom Board Shorts
Billabong Board Shorts
Quicksilver Board Shorts
Hurley Board Shorts
Quicksilveredition Board Shorts
Rusty Board Shorts
Reef Board Shorts
oneilll Board Shorts

Ezekiel surf clothing Board Shorts
Paul Frank surf clothing Board Shorts
Mada surf clothing Board Shorts
Analog surf clothing Board Shorts
Quicksilver surf clothing Board Shorts
Jet Pilot surf clothing Board Shorts
Quicksilveredition surf clothing Board Shorts
Dakine surf clothing Board Shorts
Matix surf clothing Board Shorts
Reef surf clothing Board Shorts
O'neill surf clothing Board Shorts

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 Swim Shop for swim wear wimming gear women's and men's And you must check out this website swim suit swimming suit and swim trunks Boardshorts wet suits Quiksilver Roxy Billabong Hurley Volcom Lost surf clothing