Previous | Next | Indexes
adultinternetusers > Tutorials > XSLT 2.0 Tutorial > Namespaces (4/11) >

Creating attributes in some namespace

Handling of attributes is similar to elements.
XSLT

      <xsl:stylesheet
                  xmlns:nnn="namespace-n"
                  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">
                  <ooo  nnn:a="1">
                        <xsl:apply-templates  select="*"/>
                  </ooo>
            </xsl:template>

            <xsl:template  match="bbb">
                  <zzz>
                        <xsl:attribute  name="r:x{position()}"
                                    namespace="namespace-b">222</xsl:attribute>
                  </zzz>
            </xsl:template>

            <xsl:template  match="*">
                  <xsl:element  name="{name()}:fff"
                              namespace="namespace-{position()}">
                        <xsl:attribute  name="{name()}:y"
                                    namespace="namespace-{position()}">
                              <xsl:value-of  select="position()"/>
                        </xsl:attribute>
                  </xsl:element>
            </xsl:template>

      </xsl:stylesheet>
XML

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

      <ooo
                  xmlns:nnn="namespace-n"
                  nnn:a="1">
            <zzz
                        xmlns:r="namespace-b"
                        r:x1="222"/>
            <ccc:fff
                        xmlns:ccc="namespace-2"
                        ccc:y="2"/>
            <ddd:fff
                        xmlns:ddd="namespace-3"
                        ddd:y="3"/>
      </ooo>


Previous chapter: Multiple Outputs
Next chapter: Keys
Previous page: Dynamically generated namespaces
Next page: Matching nodes in non-null namespace

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 ing suit and swim trunks