This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: union and 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]