xsl-list
[Top] [All Lists]

RE: Combining two node Sets into one

2005-04-01 12:24:01
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(_at_)mulberrytech(_dot_)com] 
Sent: Thursday, March 31, 2005 5:38 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] 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(_at_)mulberrytech(_dot_)com
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
======================================================================


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>