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

Re: Merging Two Nodesets .. can it be done?

Subject: Re: Merging Two Nodesets .. can it be done?
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Tue, 14 Aug 2007 13:37:56 +0530
Re:  Merging Two Nodesets .. can it be done?
If the structure of your input XML is fixed, we can achieve the
desired output by hardcoding the structure. I can suggest something
like below:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

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

  <xsl:template match="/X">
    <X>
      <Y>
        <Z>
          <xsl:copy-of select="Y/Z/*" />
        </Z>
        <xsl:for-each select="Y">
           <xsl:copy-of select="*[not(*)]" />
        </xsl:for-each>
      </Y>
    </X>
  </xsl:template>

</xsl:stylesheet>

But if you want the stylesheet to be generic, which could handle any
input XML, and merge the nodes, I think it will be slightly difficult
to write such a stylesheet.

On 8/14/07, Wasiq Shaikh <wasiq911@xxxxxxxxxxx> wrote:
> Quick question .. is there a way to merge two node-sets in XSL that have
> similar structure?
>
> Example Input: (generated output from XSLT)
>
> <X>
>   <Y>
>      <aaa>
>      <Z>
>         <bbb>
>         <ccc>
>      </Z>
>   </Y>
>   <Y>
>      <ddd>
>      <eee>
>      <Z>
>         <fff>
>      </Z>
>   </Y>
> </X>
>
> Desired Output: (This is how I would like to get it in the same XSLT
> process)
>
> <X>
>   <Y>
>      <Z>
>         <bbb>
>         <ccc>
>         <fff>
>      </Z>
>      <aaa>
>      <ddd>
>      <eee>
>   </Y>
> </X>
>
> Notice the Y elements are merged, as well as the Z elements.
>
> Is there any function or algorithm out there that can do this in one shot
> (or at all)? Or do I have to turn this into a two step process by making the
> generated output an input do another XSL that does the merge?
>
> Thanks for any insight!
>
> W.S


-- 
Regards,
Mukul Gandhi

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.