Mega Code Archive

 
Categories / XML / XSLT StyleSheet
 

Deal with the node with namespace

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