[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Copy idiom and overriding namespaces: trying to be sma

Subject: Copy idiom and overriding namespaces: trying to be smart, finding approaches
From: Abel Braaksma Online <abel.online@xxxxxxxxx>
Date: Wed, 26 Jul 2006 20:10:28 +0200
thanksgiving idiom
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.