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

XML
1. CSS Style
2. SVG
3. XML Schema
4. XQuery
5. XSLT stylesheet
Java
XML Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
XML » XSLT stylesheet » Namespace 
Deal with the node with namespace



File: Data.xml

<myNamespace:Book xmlns:myNamespace="http://www.java2java.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.java2java.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.java2java.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.java2java.com/namespaces</b>
                 .
               
      </paragraph>
   </body>
</html>

 
Related examples in the same category
1. namespace axis
2. Namespace alias
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.