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

Re: xml to xml mapping - how to combine two groups

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

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-2011 All Rights Reserved.