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

Re: union and difference

Subject: Re: union and difference
From: tcn@xxxxxxxxxxxxx (Trevor Nash)
Date: Sun, 13 May 2001 10:51:23 GMT
xml union difference
>i have two sets in my xml{A,B,C,D} {C,D,E,F} and i want to get the 
>intersections and those elements in 1st set but not 2nd. but
>there are two ways in examples to get result in example but only i can get 
>one working. The 1st intersection method has not results
>and the elements in 1st but not  2nd. Why does method with count not work
>

I can see two things wrong.

First, your declarations:
>	<xsl:variable name="set1" select="set1"/>
>	<xsl:variable name="set2" select="set2"/>

This gives you node sets containing XML elements, i.e. things like
<set1>A</set1>.  You should not expect <set1>C</set1> to be the same
element (in the sense of union) as <set2>C</set2>, though an equality
test *will* work because the nodes are compared in terms of their
string value ("C"="C").

 You may have tried something like

	<xsl:variable name="set1" select="set1/text()"/>

and found that this is even worse.  The reason is that XSLT joins
adjacent text nodes together, so what you get here is *one* text node
containing "ABCD" rather than four separate ones.

Second, in your XML
><Sets>
><set1>A</set1><set1>B</set1><set1>C</set1><set1>D</set1>
><set2>C</set2><set2>D</set2><set2>E</set2><set2>F</set2>
></Sets>
the text node containing "C" from set1 is *different* to the text node
containing "C" from set2.  So even without the merging mentioned
above, in your expression

>	<xsl:for-each select="$set1[count(.|$set2)=count($set2)]">

count(.|$set2) would *always* evaluate to 5, never 4.  To be treated
as the same node, the node really must be the identical node from the
original document.  Even a copy via xsl:copy or xsl:copy-of will still
be *different* nodes.

I won't try to fix your XSLT, as yo seem to be experimenting with the
techniques rather than solving an actual problem.  I hope the above is
clear - it is not an easy thing to explain.

Regards,
Trevor Nash

 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.