xsl-list
[Top] [All Lists]

RE: XMLNS and XSL

2003-02-13 15:52:21
[abdu(_dot_)r(_dot_)el-whidi(_at_)desjardins(_dot_)com]
I am new to this. and have a question to anyone who may help 
me. Thanks in advance.

We wrote an XSL that translates an XML to an HTML document.  
It worked fine until the client added default name space like this:

      <doc_root   xmlns="http://www.client.com/2001/XMLSchema"; >

If I replace the xmlns="", it will work as before.  If I keep 
it.  Non of the XSLT will be performed.  I know it has to do 
with name space defaulting, But I could not get it.

here are the headers from my xsl file:

      <?xml version='1.0' encoding='iso-8859-1' ?>
      <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >


David Bertoni just answered this for another post.  Check out those FAQ
references.

Your "doc_root" element is now in a namespace,and your stylesheet has to

1) declare that namespace, and
2) look for elements to match using that namespace.

To declare it, assign a prefix -

 <?xml version='1.0' encoding='iso-8859-1' ?>
       <xsl:stylesheet version="1.0"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
      xmlns:doc='http://www.client.com/2001/XMLSchema'>

It does not matter what you call the prefix, as long as you assign one
to that namespace.

Next, use the prefix when you call for matches, like this:

<xsl:template match='/doc:doc_root'>
...
</xsl:template>

If you do not use the prefix, the match is specified to be in no
namespace, so naturally it will not match any of your elements since
they are in the "http://www.client.com/2001/XMLSchema"; namespace.

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>