Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] xml to xml mapping - how to combine two groups

From: "Jay Bryant" <jay@------------>
To:
Date: 1/3/2008 10:42:00 PM
Hi, Andy,



It's very possible. Here's one way.



First, here's your source XML snippet with an additional parent element (so 
that I could test):



<WRAPPER>
 <LIST_CREATION>
   <CREATION>
     <CREATION_DATE>03-OCT-07</CREATION_DATE>
   </CREATION>
 </LIST_CREATION>
 <LIST_NOTE>
   <NOTE>
     <OUT_NOTE>Blue Box</OUT_NOTE>
   </NOTE>
   <NOTE>
     <OUT_NOTE>Red Box</OUT_NOTE>
   </NOTE>
 </LIST_NOTE>
</WRAPPER>

And here's a transform that produces your desired output.



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">



 <xsl:output method="xml" indent="yes"/>



 <xsl:template match="*"/>



 <xsl:template match="WRAPPER">
   <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match="LIST_CREATION">

   <LIST_COMBINED>

     <COMBINED>

       <xsl:copy-of select="CREATION/CREATION_DATE"/>

       <xsl:copy-of select="../LIST_NOTE/NOTE[1]/OUT_NOTE"/>

     </COMBINED>

     <COMBINED>

       <xsl:copy-of select="../LIST_NOTE/NOTE[position() &gt; 
1]/OUT_NOTE"/>

     </COMBINED>

   </LIST_COMBINED>

 </xsl:template>



</xsl:stylesheet>



I can think of other ways to do this (via apply-templates, for one), but 
this is one possible way.



I tested with Saxon 8.9.



Jay Bryant
Bryant Communication Services
http://www.bryantcs.com


----- Original Message ----- 
From: <Andy.Lewis@xxxxxxxxxxx>

To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>

Sent: Thursday, January 03, 2008 4:00 PM

Subject: [xsl] xml to xml mapping - how to combine two groups








Hello,



I have the following xml data:



<LIST_CREATION>
<CREATION>
<CREATION_DATE>03-OCT-07</CREATION_DATE>
</CREATION>
</LIST_CREATION>
<LIST_NOTE>
<NOTE>
<OUT_NOTE>Blue Box</OUT_NOTE>
</NOTE>
<NOTE>
<OUT_NOTE>Red Box</OUT_NOTE>
</NOTE>
</LIST_NOTE>


I need to map these into one grouping.
I would like the result to be something like:

<LIST_COMBINED>
<COMBINED>
<CREATION_DATE>03-OCT-07</CREATION_DATE>
<OUT_NOTE>Blue Box</OUT_NOTE>
</COMBINED>
<COMBINED>
<OUT_NOTE>Red Box</OUT_NOTE>
</COMBINED>
</LIST_COMBINED>

If this is possible, I would much appreciate some guidance!!



Thanks! Andy




This message may contain confidential and/or privileged information. This 
information is intended to be read only by the individual or entity to whom 
it is addressed. If you are not the intended recipient, you are on notice 
that any review, disclosure, copying, distribution or use of the contents of 
this message is strictly prohibited. If  you have received this message in 
error, please notify the sender immediately and delete or destroy any copy 
of this message.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent