Deal with the node with namespace : Namespace « XSLT stylesheet « XML

Home
XML
1.CSS Style
2.SVG
3.XML Schema
4.XQuery
5.XSLT stylesheet
XML » XSLT stylesheet » Namespace 
Deal with the node with namespace



File: Data.xml

<myNamespace:Book xmlns:myNamespace="http://www.java2s.com/namespaces">
 <myNamespace:Chapter number="1">chapter 1</myNamespace:Chapter>
 <myNamespace:Chapter number="2">chapter 2</myNamespace:Chapter>
</myNamespace:Book>

File: Transform.xslt

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:myNamespace="http://www.java2s.com/namespaces">
  <xsl:template match="/">
    <html>
      <head>
        <title>This shows namespace nodes.</title>
      </head>
      <body>
        <h3>
          Namespace nodes of the myNamespace:Book element.
        </h3>
        <xsl:apply-templates select="/myNamespace:Book" />
      </body>
    </html>
  </xsl:template>

  <xsl:template match="myNamespace:Book">
    <xsl:for-each select="namespace::node()">
      <paragraph>
        <xsl:value-of select="position()" />
        . The namespace prefix
        <b>
          <xsl:value-of select="name(.)" />
        </b>
        has the namespace URI
        <b>
          <xsl:value-of select="." />
        </b>
        .
      </paragraph>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
Output:

<html xmlns:myNamespace="http://www.java2s.com/namespaces">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>This shows namespace nodes.</title>
   </head>
   <body>
      <h3>
                   Namespace nodes of the myNamespace:Book element.
                 
      </h3>
      <paragraph>1
                 . The namespace prefix
                 <b>xml</b>
                 has the namespace URI
                 <b>http://www.w3.org/XML/1998/namespace</b>
                 .
               
      </paragraph>
      <paragraph>2
                 . The namespace prefix
                 <b>myNamespace</b>
                 has the namespace URI
                 <b>http://www.java2s.com/namespaces</b>
                 .
               
      </paragraph>
   </body>
</html>

 
Related examples in the same category
1.namespace axis
2.Namespace alias
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.