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

Matching all elements in selected namespace

It is possible to match only elements in the selected namespace. Please note, that aaa is not in any namespace and so match = "aaa" can be used. If match = "*", then nodes in any namespace are matched.

XSLT

      <xsl:stylesheet
                  xmlns:o="oooooo"
                  xmlns:p="pppppp"
                  xmlns:v="vvvvvv"
                  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">
                  <zzz>
                        <vvv>
                              <xsl:apply-templates  select="v:*"/>
                        </vvv>
                        <ooo>
                              <xsl:apply-templates  select="o:*"/>
                        </ooo>
                        <ppp>
                              <xsl:apply-templates  select="p:*"/>
                        </ppp>
                  </zzz>
            </xsl:template>

            <xsl:template  match="*">
                  <xsl:copy-of  select="."/>
            </xsl:template>

            <xsl:template  match="p:*">
                  <XYZ>
                        <xsl:copy-of  select="."/>
                  </XYZ>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa
                  xmlns:o="oooooo"
                  xmlns:p="pppppp"
                  xmlns:v="vvvvvv">
            <o:bbb/>
            <v:ccc/>
            <o:ddd/>
            <v:eee/>
            <p:fff/>
            <p:ggg/>
      </aaa>
Output

      <zzz
                  xmlns:o="oooooo"
                  xmlns:p="pppppp"
                  xmlns:v="vvvvvv">
            <vvv>
                  <v:ccc/>
                  <v:eee/>
            </vvv>
            <ooo>
                  <o:bbb/>
                  <o:ddd/>
            </ooo>
            <ppp>
                  <XYZ>
                        <p:fff/>
                  </XYZ>
                  <XYZ>
                        <p:ggg/>
                  </XYZ>
            </ppp>
      </zzz>


Previous chapter: Multiple Outputs
Next chapter: Keys
Previous page: Matching nodes in non-null namespace
Next page: Namespace propagation from source to result