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

RE: Combining two node Sets into one

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

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:exsl="http://exslt.org/common"
                extension-element-prefixes="exsl"
                version="1.0">
  ...
  <!-- 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:  Combining two node Sets into one


Chris,

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="/">
   <Trans>
     <xsl:apply-templates select="//Disbs | //Refunds">
       <xsl:sort select="DisbDetail/Ddate | RefDetail/Rdate"/>
     </xsl:apply-templates>
   </Trans>

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">
   <xsl:apply-templates/>
   <!-- nothing to be done here except select and process our
        children, which will map -->
</xsl:template>

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

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

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 -->
   <TranDetail>
     <!-- but here we need to announce our type: -->
     <Ttype>refund</Ttype>
     <xsl:apply-templates/>
   </TranDetail>
</xsl:template>

... 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 -->
   <TranDetail>
     <!-- but here we need to announce our type: -->
     <Ttype>
       <xsl:choose>
         <xsl:when test="self::DisbDetail">dis</xsl:when>
         <xsl:otherwise>refund</xsl:otherwise>
       </xsl:choose>
     </Ttype>
     <xsl:apply-templates/>
   </TranDetail>
</xsl:template>

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.

Cheers,
Wendell


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
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

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.