Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: David Carlisle <davidc@--------->
To:
Date: 7/1/2004 4:10:00 PM
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
________________________________________________________________________


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent