RE: [xsl] Copy idiom and overriding namespaces: trying to be smart, finding approaches

Subject: RE: [xsl] Copy idiom and overriding namespaces: trying to be smart, finding approaches
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 26 Jul 2006 19:32:59 +0100
I'm not at all sure what you're trying to do here, but

match="*[local-name() = '']

looks all wrong. Every element has a local name.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Abel Braaksma Online [mailto:abel.online@xxxxxxxxx] 
> Sent: 26 July 2006 19:10
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Copy idiom and overriding namespaces: trying 
> to be smart, finding approaches
> 
> Dear List,
> 
> Working through some lists of examples online and in books, I 
> found some ways of overriding the target namespace, but 
> strangely enough, all seem to create an explicit name for 
> elements with a namespace prefix that contains a certain 
> namespace. I don't think that is in the true nature of 
> namespace, even more so, because ns prefixes are just 
> placeholders for the namespace and should not be manipulated by hand.
> 
> Actually, I am just looking for the best xslt-minded approach 
> here. The solution below works, but I would like some expert 
> opinion on it. Just using "copy-namespace" does not work, as 
> the namespace fixup process will set the original namespace back.
> 
> Requirement:   Let the calling program decide what the target 
> namespace 
> will be.
> Input:         any document or node
> Parameters:    $target-namespace, a string representing the 
> target namespace
> 
>     <!-- matches all attributes and all elements,
>            except for elements that have a name -->
>     <xsl:template match="*[local-name() = ''] | @*" >
>         <xsl:copy copy-namespaces="no">
>             <xsl:apply-templates select="@* | node()" />
>         </xsl:copy>
>     </xsl:template>
>    
>     <!-- matches only elements that have a name,
>            excluding text nodes, attributes etc -->
>     <xsl:template match="*[local-name() != '']" >
> 
>         <!-- assign namespace -->
>         <xsl:element
>              name="{local-name()}"
>              namespace="{$target-namespace}">
> 
>             <xsl:apply-templates  select="@* | node()" />
>         </xsl:element>
>     </xsl:template>
> 
> 
> Best regards,
> 
> Abel Braaksma
> www.nuntia.nl

Current Thread