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

Re: Node comparison

Subject: Re: Node comparison
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sun, 15 Apr 2001 15:26:26 +0100
null value comparison in xsl
Hi Kevin,

> Having two different XML's joined on an entity reference I need to
> compare values underneath two different parent nodes without having
> to use a $Position Variable. The reason being is that I may not have
> a one to one relationship. So with an example below I would like to
> use my XSLT to base the values of Parent 2 on the like values in
> Parent 1.

The XML that you gave (as both source and result) isn't well formed.
I guess you actually mean something like:

<Parent num="1">
  <Value num="1">1</Value>
  <Value num="2">0</Value>
  <Value num="3">1</Value>
  <Value num="4">0</Value>
</Parent>
<Parent num="2">
  <Value num="1"> </Value>
  <Value num="2"> </Value>
  <Value num="2"> </Value>
  <Value num="3"> </Value>
  <Value num="4"> </Value>
</Parent>

So, you have an attribute (or something) in the Value elements that
shows what value they should take.  The result should copy the first
Parent element and everything in it:

  <xsl:copy-of select="Parent[@num = '1']" />

It should then create a Parent element with a num attribute equal to
2 (essentially a copy of the second Parent element):

  <Parent num="2">
     ...
  </Parent>

And within that you want to process each of the Value elements under
the second Parent element.  For each of those Value elements, you want
to get the Value element within the first Parent element whose num
attribute is equal to the num attribute of the Value element that
you're processing (the current node):

  <Parent num="2">
    <xsl:variable name="parent1" select="Parent[@num = '1']" />
    <xsl:for-each select="Parent[@num = '2']/Value">
       <xsl:variable name="num" select="@num" />
       <Value num="{$num}">
          <xsl:value-of select="$parent1/Value[@num = $num]" />
       </Value>
    </xsl:for-each>
  </Parent>

You might find it more efficient to use a key to get the relevant
values.  You could create a key to index into the Value elements
within the first Parent by their num attribute:

<xsl:key name="values" match="Parent[@num = '1']/Value" use="@num" />

You can then get the relevant Value element with the key() function:

  <Parent num="2">
    <xsl:for-each select="Parent[@num = '2']/Value">
       <Value num="{@num}">
          <xsl:value-of select="key('values', @num)" />
       </Value>
    </xsl:for-each>
  </Parent>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.