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: Fri, 2 Jul 2004 10:18:20 +0100
> 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

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

> <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:element name="{$prefix}:{local-name()}">
    <xsl:copy-of select="@*"/>

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

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.


The LaTeX Companion

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:

Current Thread