Learn XML, XSLT, XPath with Tutorials & Samples


namespace-uri
XML XSL

<?xml-stylesheet type="text/xsl" href="myFile.xslt"?>
<b:store xmlns:b="x-schema:MySchema.xml">
  <b:book id="B1">
    <b:title>XML</b:title>
    <b:author>Bill</b:author>
    <b:price>25</b:price>
  </b:book>
</b:store>



mySchema.xml

<Schema name="books" xmlns="urn:schemas-microsoft-com:xml-data"
           xmlns:dt="urn:schemas-microsoft-com:datatypes">

  <ElementType name="title"/>
  <ElementType name="author"/>
  <ElementType name="price"/>
  <AttributeType name="id" dt:type="id"/>

  <ElementType name="store">
    <element type="book"/>
  </ElementType>

  <ElementType name="book" model="closed" content="eltOnly">
    <attribute type="id"/>
    <element type="title"/>
    <element type="author"/>
    <element type="price"/>
  </ElementType>
</Schema>

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>

  <xsl:template match="/">
    <html>
      <body>
        <table border="1">
          <tr>
            <th>namespace-uri()</th>
            <th>name()</th>
            <th>local-name</th>
            <th>text()</th>
          </tr>

          <xsl:apply-templates />

        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="*">

    <tr>
      <td><xsl:value-of select="namespace-uri()"/></td>
      <td><xsl:value-of select="name()"/></td>
      <td><xsl:value-of select="local-name()"/></td>
      <td><xsl:value-of select="text()"/></td>
    </tr>

    <xsl:apply-templates select="*"/>

  </xsl:template>

</xsl:stylesheet>


OutPut:

namespace-uri() name() local-name text()
x-schema:MySchema.xml b:store store
x-schema:MySchema.xml b:book book
x-schema:MySchema.xml b:title title XML
x-schema:MySchema.xml b:author author Bill
x-schema:MySchema.xml b:price price 25