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

RE: Namespace de-duplication for dynamically generated

Subject: RE: Namespace de-duplication for dynamically generated elements
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 9 Sep 2008 09:44:30 +0100
RE:  Namespace de-duplication for dynamically generated
At the point where you generate the top-level element, do 

<output>
  <xsl:copy-of select="/order/namespace::*"/>

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

> For reasons which I won't bore you with, we have an input XML 
> format of the style:
> 
> customer1.xml:
> <order xmlns:pt="urn:ex">
>     <foo name="pt:zip"> apple </foo>
>     <foo name="pt:zap"> orange </foo>
> </order>
> 
> customer2.xml:
> <order xmlns:go="urn:ex">
>     <foo name="go:zip"> pear </foo>
>     <foo name="go:zap"> banana </foo>
> </order>
> 
> We want a single XSLT which will handle these without a 
> priori knowledge of the QNames or namespace *inside* the 
> @name attribute.  We need to transform these into:
> 
> customer1-out-desired.xml:
> <output xmlns:pt="urn:ex">
>     <pt:zip> apple </pt:zip>
>     <pt:zap> orange </pt:zap>
> </output>
> 
> customer2-out-desired.xml:
> <output xmlns:go="urn:ex">
>     <go:zip> pear </go:zip>
>     <go:zap> banana </go:zap>
> </output>
> 
> After a long struggle, I've managed some hacky XSLT which 
> manages the namespace mapping from strings and NS 
> declarations to prefixed QName elements, however I end up 
> getting the xmlns:pt="urn:ex" element on
> *every* leaf element (e.g. <go:zip xmlns:go="urn:ex">), 
> rather than just once on the document element as I would like it:
> 
> 
> customer1-out-actual.xml:
> <output>
>     <pt:zip xmlns:pt="urn:ex"> apple </pt:zip>
>     <pt:zap xmlns:pt="urn:ex"> orange </pt:zap> </output>
> 
> customer2-out-actual.xml:
> <output>
>     <go:zip xmlns:go="urn:ex"> pear </go:zip>
>     <go:zap xmlns:go="urn:ex"> banana </go:zap> </output>
> 
> Does anyone know of any tricks to avoid this situation?
> 
> Cheers,
> 
> Ian
> 
> PS - The relevant XSLT snippet I've written is:
> 
>   <xsl:template match="foo">
>     <xsl:element name="{substring-after(@name,':')}"
>       
> namespace="{namespace-uri-for-prefix(substring-before(@name,':'),.)}">
>        <xsl:value-of select=".">
>     </xsl:element>
>     </xsl:template>
> 
> --
> Ian.Stokes-Rees@xxxxxxxxxxxx +1 (617) 418-4168 SP Metric 
> Limited, Technology Consulting

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.