[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Mapping Elements into New Namespaces


Subject: RE: [xsl] Mapping Elements into New Namespaces
From: Américo Albuquerque <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Fri, 31 Jan 2003 10:44:56 -0000

Hi Dan.
You could pass your new namespace as a parameter and use <xsl:element>
to copy your elements with the new namespace.
Hope this helps.

 <xsl:template match="a:PartAB">
 <Part1 xmlns="http://www.bbb.com">
  <!-- copying the child elements in the new $ns namespace -->
  <xsl:apply-templates>
   <xsl:with-param name="ns" select="'http://www.bbb.com'"/>
  </xsl:apply-templates>
 </Part1>
 </xsl:template>
 
 <xsl:template match="a:PartCD">
 <Part2 xmlns="http://www.bbb.com">
  <v:Details xmlns="http://www.ccc.com" xmlns:v="http://www.bbb.com">
  <!-- copying the child elements in the new $ns namespace -->
  <xsl:apply-templates>
   <xsl:with-param name="ns" select="'http://www.ccc.com'"/>
  </xsl:apply-templates>
  </v:Details>
 </Part2>
 </xsl:template>
 
 <xsl:template match="*">
  <!-- the default namespace will be the elements' namespace -->
  <xsl:param name="ns" select="namespace-uri()"/>
  <xsl:element name="{name()}" namespace="{$ns}">
   <xsl:apply-templates/>
  </xsl:element>
 </xsl:template>


-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Dan Diebolt
Sent: sexta-feira, 31 de Janeiro de 2003 10:04
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Mapping Elements into New Namespaces


Greatly simplified, I have source XML that looks like this

File: Source.xml
================
<?xml version="1.0"?>
<Root xmlns="http://www.aaa.com">
 <PartAB>
  <A>1</A>
  <B>2</B>
 </PartAB>
 <PartCD>
  <C>3</C>
  <D>4</D>
 </PartCD>   
</Root>

And I need to transform it into this output format:

File: Target.xml
================
<?xml version="1.0"?>
<Output>
 <Parts  xmlns="http://www.bbb.com">
  <Part1>
   <A>1</A>
   <B>2</B>
  </Part1>
  <Part2>
   <v:Details xmlns="http://www.ccc.com" xmlns:v="http://www.bbb.com">
    <C>3</C>
    <D>4</D>   
   </v:Details>
  </Part2>
 </Parts>
</Output>

I am having trouble transforming <C> and <D> because of the changed
default namespace on <Details>. Can someone suggest how to accomplish
this? I do not have control over the structure of the elements and 
namespaces in Target.xml. Copy to dandiebolt@xxxxxxxxx would help as 
I am on digest. Thanks in advance. 



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords
xml