Jump to content

Understanding XML namespaces

Recommended Posts

Hello, I am having difficulty understanding how namespaces work.  To my understanding, the namespace URI is added to an xml document with a qualifier so you can contextualize the content (i.e. differentiate two complex elements with the name "table" that may have different elements and attributes).  I understand that the URI is not looked up, but rather to give the namespace a global unique identifier.  This is where my confusion begins.  Take for instance the following xml:

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"

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



to my understanding, the elements or attributes prefixed with xsl (xsl:template, xsl:for-each, etc.), the XML parser recognizes to be part of the "http://www.w3.org/1999/XSL/Transform" namespace.  My question is, if the URI is not used to lookup content, how does it check that the elements provided are all (valid) in the xsl prefixed namespace, or does it?  What I do not understand is the following from the XSL Transformation Page, it states the following 

<xsl:stylesheet version="1.0"

To get access to the XSLT elements, attributes and features we must declare the XSLT namespace at the top of the document.

How do we have "access" to elements, attributes, and features if no lookup is done?

For instance, if I added the following element to the xml file:

<xsl:foo>Made up element</xsl:foo>

what happens? I know that foo is not a defined element inside of the xsl namespace, but how does a XML parser know that? 


How does the parser know what elements should/could be inside the prefixed namespace?  


Thanks in advance!

Edited by RikP
spelling, format
Link to post
Share on other sites

I assume that if something understands XSLT, then that definition is built-in to whatever software you're using, and it just checks the namespace identifier to make sure that it's actually XSLT that you're trying to use.  Support for that would be built-in to the software though, it's not going to pull up that human-readable web page and try to get some kind of definition out of it, that URL is for people to read.  This is an example of a DTD which defines a particular schema:


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...