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

Discovering available namespaces on the element

In XPath 1.0 "namespace::" axis was used for namespace discovery. In XPath 2.0 this axis was deprecated and XPath 2.0 compatible processors are not required to support this axis.

Functions in-scope-prefixes() and namespace-uri-for-prefix() are used for this task.

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="/aaa">
                  <xxx>
                        <xsl:for-each  select="descendant::*">
                              <xsl:variable  name="v"
                                          select="."/>
                              <el  name="{name($v)}">
                                    <xsl:for-each  select="in-scope-prefixes(.)">
                                          <nm  prefix="{.}"
                                                      namespace="{namespace-uri-for-prefix(.,$v)}"/>
                                    </xsl:for-each>
                              </el>
                        </xsl:for-each>
                  </xxx>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <o:bbb
                        xmlns:o="oooooo">
                  <p:ccc
                              xmlns:p="pppppp"/>
            </o:bbb>
            <ccc
                        xmlns:="cccccc"/>
      </aaa>
Output

      <xxx>
            <el  name="o:bbb">
                  <nm  prefix="xml"
                              namespace="http://www.w3.org/XML/1998/namespace"/>
                  <nm  prefix="o"
                              namespace="oooooo"/>
            </el>
            <el  name="p:ccc">
                  <nm  prefix="xml"
                              namespace="http://www.w3.org/XML/1998/namespace"/>
                  <nm  prefix="o"
                              namespace="oooooo"/>
                  <nm  prefix="p"
                              namespace="pppppp"/>
            </el>
            <el  name="ccc">
                  <nm  prefix="xml"
                              namespace="http://www.w3.org/XML/1998/namespace"/>
                  <nm  prefix=""
                              namespace="cccccc"/>
            </el>
      </xxx>


Previous chapter: Multiple Outputs
Next chapter: Keys
Previous page: Namespace creation
Next page: - - -

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