Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of XMLNS URL in xml document

i want to know, is there any real meaning of xmlns urls in xml document ?

i had refer to link . now when i change the xmlns:xsl="http://www.w3.org/1999/XSL/Transform" to something else, it stopped working. w3c says namespace names(OR URL) is just for to distinguish xml tags. than why it is not working after changing url.

so i thought, may be it has something to do with that URL, so tried localy (without internet).. see following example..

XML Document. (first.xml)

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="first.xsl"?>
<!-- Edited by XMLSpy® -->
<catalog>
    <cd>
        <title>Unchain my heart</title>
        <artist>Joe Cocker</artist>
        <country>USA</country>
        <company>EMI</company>
        <price>8.20</price>
        <year>1987</year>
    </cd>
     <cd>
        <title>Pavarotti Gala Concert</title>
        <artist>Luciano Pavarotti</artist>
        <country>UK</country>
        <company>DECCA</company>
        <price>9.90</price>
        <year>1991</year>
    </cd>
    <cd>
        <title>The dock of the bay</title>
        <artist>Otis Redding</artist>
        <country>USA</country>
        <company>Atlantic</company>
        <price>7.90</price>
        <year>1987</year>
    </cd>
</catalog>

XSLT Document (first.xsl)

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

so, its working fine localy. but if i change xmlns:xsl="http://www.w3.org/1999/XSL/Transform" to something else like xmlns:xsl="http://www.abc.com" it gives me error in the browser.

Error loading stylesheet: Parsing an XSLT stylesheet failed.

so, the only question is, is there any real meaning of this URLS in xmlns. if yes it has than why it did worked without internet and not by changing the url in xsl.

like image 853
hardik Avatar asked Jul 22 '12 14:07

hardik


2 Answers

It's not a URL, it's a URI. That is, it's an identifier (a name), not a location (an address).

A namespace in XML is like a package name in Java; different vocabularies are defined in different namespaces to prevent conflicts and to claim ownership of the definition of the vocabulary. Like package names, the namespace becomes an implicit part of the names of elements in that namespace, so that <para> in the Docbook namespace has no connection with <para> in the DITA namespace.

James Clark wrote a good tutorial on namespaces here: http://www.jclark.com/xml/xmlns.htm

like image 198
Michael Kay Avatar answered Sep 28 '22 08:09

Michael Kay


is there any real meaning of this URLS in xmlns

This is a fundamental XML question -- not an XSLT one.

A namespace-uri serves the purpose of identifying a specific XML-based language -- by having all of the element names of this labguage in the same namespace (making all of them have that same namespace-uri).

Other than that, a namespace uri has no additional purpose.

Therefore, all XSLT elements (and some attributes) are in the "http://www.w3.org/1999/XSL/Transform" namespace and any element with name that hasn't this namespace-uri is not an XSLT element.

Here are more examples:

  • XML Schema: "http://www.w3.org/2001/XMLSchema"

  • SVG: "http://www.w3.org/2000/svg"

  • XSL-FO: http://www.w3.org/1999/XSL/Format

  • XHTML: "http://www.w3.org/1999/xhtml"

  • XPath 2.0 and XQuery functions: http://www.w3.org/2005/xpath-functions

  • XLink: "http://www.w3.org/1999/xlink"

  • MathML: "http://www.w3.org/1998/Math/MathML"

Therefore, by modifying the XSLT namespace-uri in your stylesheet to something else, you are effectively saying: The names prefixed by the associated prefix (in your case "xsl") belong to the "http://www.abc.com" namespace, not to the XSLT namespace -- therefore they are not XSLT elements.

Then of course, when an XSLT processor sees that it has been fed with elements that are not XSLT elements, the XSLT processor complains about this.

like image 23
Dimitre Novatchev Avatar answered Sep 28 '22 08:09

Dimitre Novatchev