Re: [xsl] Transforming Locally Declared Namespaces into Globally Declared Namespaces

Subject: Re: [xsl] Transforming Locally Declared Namespaces into Globally Declared Namespaces
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 1 Jul 2004 15:10:18 +0100
In theory all these things are equivalent according to the namespace rec
and so equivalent in the XPath data model and so you can not _force_
that xslt writes things one way or another: you coul just write an
identity transform and find that your XSLT system changes your document
from one style to the other.

that said, most systems don't arbitrarily change namespace prefixing
style just because they can, and do go to some effort to preserve what
they devine to be the author intention, 

so first of all you want to get some namespace nodes on to the top level
document element (this will _force_ namespace declarations of these
prefixes in the output, what you can't actually uses these prefixes).
easiest way of doing that is to declare them in the stylesheet.

<xsl:stylesheet ...
  xmlns:a="urn:a" xmlns:b="urn:b" xmlns:c="urn:c">


then in for your top level element
<xsl:template match="/a:a">
  <a:a>
     <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </a:a>
</xsl:template>

by using a literal element here you will get teh namespace nodes from
the stylesheet which you wouldn't get if you used xsl:element or
xsl:copy

for everything else you want to force a prefix so

<xsl:template match="a:*">
 <xsl:element name="a:{local-name()}">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
 </xsl:element>
</xsl:template>

<xsl:template match="b:*">
 <xsl:element name="b:{local-name()}">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
 </xsl:element>
</xsl:template>

etc.

David


-- 
The LaTeX Companion
  http://www.awprofessional.com/bookstore/product.asp?isbn=0201362996
  http://www.amazon.co.uk/exec/obidos/tg/detail/-/0201362996/202-7257897-0619804


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread