XSLT Question: Unique nodes based on 2 sub nodes

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi. I have a question using XSLT in C# (it is a XSLT question). I use a XPathDocument to load my XML, then a XslCompiledTransform to load my XSLT and then I apply the Transform method and it works fine. But I have a question for what I am trying to transform.
I use a for-each where I try to get only the last node R of a combination of 2 subnodes (X and Y). Here is an example of input

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; Data<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Records<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; R<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; X<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; X<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Y<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; Y<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Value<span style="color:Blue; >0<span style="color:Blue; </<span style="color:#A31515; Value<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; R<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; R<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; X<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; X<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Y<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; Y<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Value<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; Value<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; R<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; R<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; X<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; X<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Y<span style="color:Blue; >2<span style="color:Blue; </<span style="color:#A31515; Y<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Value<span style="color:Blue; >0<span style="color:Blue; </<span style="color:#A31515; Value<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; R<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; R<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; X<span style="color:Blue; >2<span style="color:Blue; </<span style="color:#A31515; X<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Y<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; Y<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Value<span style="color:Blue; >0<span style="color:Blue; </<span style="color:#A31515; Value<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; R<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; R<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; X<span style="color:Blue; >2<span style="color:Blue; </<span style="color:#A31515; X<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Y<span style="color:Blue; >2<span style="color:Blue; </<span style="color:#A31515; Y<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Value<span style="color:Blue; >0<span style="color:Blue; </<span style="color:#A31515; Value<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; R<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Records<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Data<span style="color:Blue; >
[/code]
In this example I would want all nodes R except the first node since the second node is also X=1,Y=1 and I only want the last node with the unique combination of X/Y.

If it was only 1 sub node (ie only unique X or only unique Y) it would be fine but I cant get it to work for the combination of 2 subnodes (ie X/Y). Let me give you my current select:
<xsl:for-each select="Data/Records/R[ X[not(.=following::X)] and Y[not(.=following::Y)] ]
It doesnt work because it only retrieves nodes R that have a "unique X" and "unique Y", not the combination of "unique X and Y".

View the full article
 
Back
Top