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

Subject: Re: [xsl] xml to xml mapping - how to combine two groups
From: "Jay Bryant" <jay@xxxxxxxxxxxx>
Date: Thu, 3 Jan 2008 16:41:09 -0600
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.


Current Thread