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/2/2004 11:18:00 AM
> I had hoped for a more generic solution because we are working with
> arbitrary schema.

It's probably possible to do something more generic but it all
depends...

for example, instead of hardcoding a set of namespace templates in the
stylesheet

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

You could do

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



where .... hmmm  .... is replaced by er something.
the requirements being that
a) you want to get the same prefix for every element in each namespace
b) you want a different prefix for each namespace
c) you want a namespace node declaring that prefix on the top most
    element of the output

One way to achieve that, as in my first post was to assume you know all
teh namespaces that can occur, and arbitrarily assign them fixed
prefixes in the stylesheet, ignoring any prefixes used (or not) in the
source.

If you can't make that assumption, you have to work a bit harder.
eg if you keyed every element by its namespace

<xsl:key name="ns" match="*" use="namespace-uri()"/>

then hmm could be

<xsl:value-of select="generate-id(key('ns',namespace-uri(current()))[1])"/>

whch would use as a prefix a (generated) id of the first element in the
source that had that namespace, so clearly that satisfies a and b above.
to satisfy c you'd have to use a node-set extension function:
First generate the output as above into a variable, then use node-set so
you can post process the variable, and then just xsl:copy-of all teh
namespace nodes up to the top.


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