RE: [xsl] Combining two node Sets into one

Subject: RE: [xsl] Combining two node Sets into one
From: "Williamson, Chris" <cwilliamson@xxxxxxxxx>
Date: Fri, 1 Apr 2005 14:24:01 -0500
I solved the problem by using..

<xsl:stylesheet xmlns:xsl="";
  <!-- Now we can convert result tree fragment back to node-set -->
  <xsl:value-of select="exsl:node-set($author)/email"/>

But how does this effect the output for browsers such as mozilla, netscape,
and IE?  Will the browsers act differently?

-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx] 
Sent: Thursday, March 31, 2005 5:38 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Combining two node Sets into one


At 03:27 PM 3/31/2005, you wrote:
>Is there any possible way to combine two node sets into one single node 
>set (assign to variable?) and then add an extra childnode to the set 
>based on which parent node the new node came from.

Sure, this is a fairly straightforward "plain vanilla" XML->XML 
transformation, maybe with a few sprinkles....

You'll need at some point to select all the Disbs and Refunds elements 
together -- that's where you'll do your sorting by date, and also where 
you'll create the wrapper for the entire output:

<xsl:template match="/">
     <xsl:apply-templates select="//Disbs | //Refunds">
       <xsl:sort select="DisbDetail/Ddate | RefDetail/Rdate"/>

Now you need templates to match the Disbs and Refunds elements, and for 
their descendants in turn (which will map to your new elements). I'll just 
show you a couple of them:

<xsl:template match="Disbs">
   <!-- nothing to be done here except select and process our
        children, which will map -->

<xsl:template match="DisbDetail">
   <!-- maps to TranDetail -->
     <!-- but here we need to announce our type: -->
   <!-- descends another level -->

<xsl:template match="Damount">

and so forth.

Once you've got all these templates, you'll find many of them are very 
similar ... for example you'll have

<xsl:template match="RefDetail">
   <!-- maps to TranDetail, and descends another level -->
     <!-- but here we need to announce our type: -->

... notice this is almost exactly like the template matching DisbDetail. 
(The one matching Ramount will be exactly like the one matching Damount.)

So they can be combined:

<xsl:template match="DisbDetail | RefDetail">
   <!-- maps to TranDetail, and descends another level -->
     <!-- but here we need to announce our type: -->
         <xsl:when test="self::DisbDetail">dis</xsl:when>

Your entire stylesheet will have just a few fairly simple templates.

I hope that helps! If anything here is mysterious to a newbie, my guess 
it'll be about how templates match and how xsl:apply-templates works ... 
the famous XSLT processing model.


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
   Mulberry Technologies: A Consultancy Specializing in SGML and XML

Current Thread