RE: [xsl] Namespaces II

Subject: RE: [xsl] Namespaces II
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Wed, 2 Jul 2003 13:37:55 +0100
> that stops _other_ namespace nodes being copied but as I said in my
> forst reply, you don't want a copy at all as you need to change the name
> of the element from p in urn:DTD930 to p in no namespace.
> 
> So you need to have a template that matches the former and generates the
> latter.

Yes, it's good to be aware that node and namespace are not two separate things, they are forever joined and merely reference two different bits of a node's qName.

For example, if you have:

<my:test>

The real name (qName) of the node is the fully expanded name.  So if you have stated the 'my' prefix to be 'http://www.mydomain.com' the actual name of the node is:

<http://www.mydomain.com:test/>

*not* something like:

<test namespace="http://www.mydomain.com"/> 

You can use the namespace prefix to save your fingers, and to make the code readable, but ultimately it doesn’t separate the namespace from the node.  The namespace should unique, so its common to use url's, although you can use whatever you want.

So the thing to remember is: when you copy a node the namespace is an intrinsic part the node, and comes too.

If you want a node with the same name but in a different namespace, you have to create a new node using the local-name() of the original, give it a new namespace (if any), then copy through the contents of the original.  Something like:

  <xsl:element name="foo" namespace="someurl">
      <xsl:copy-of select="child::node()"/>
  </xsl:element>


cheers
andrew

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003
 

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


Current Thread