Re: [xsl] counting elements with values that match other element values

Subject: Re: [xsl] counting elements with values that match other element values
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 18 May 2006 14:11:16 +0100
I'd do this using muenchian grouping:

<xsl:key name="c" match="cSet/c" use="."/> 


<xsl:copy-of select="/root/t/cSet/c[generate-id(key('c',.)[2])=generate-id(.)]"/>


which returns 

which seems to be the right answer as all those ar used twice I think.

> mostly I'm asking for how the parser is reading the expression I
> wrote, 
which is

  //root/ccc/c[ count(  //root/t[  h =1  and  . =   cSet/c    ]   ) &gt; 0     ] 

starting at the left //root means search the entire document to
arbitrary depth looking for root elements which is quite expensive (I'd
say especially as you do it twice, but I think saxon will only do it
once anyway) you mean /root there.

that selects all the c's under ccc but the predicate inside the
following [] does not use any relative paths so it's value does not
depend on the particular c element (as they are all in the same
document) so this expression is a constant in the loop and may be pulled
out so it's equivalent to
<xsl:variable name="x" select="boolean(count(  //root/t[  h =1  and  . =   cSet/c    ]   ) &gt; 0 )]"/>
select=" //root/ccc/c[$x]"
which is either //root/ccc/c or eth empty node set depending on whether
$x is true().

boolean(count(  //root/t[  h =1  and  . =   cSet/c    ]   ) &gt; 0 )
true just if
 //root/t[  h =1  and  . =   cSet/c    ] 
is non-empty
in this case h is always 1 (and root is at teh top) so we can simplify to

 /root/t[  . =   cSet/c    ] 

which selects all t elements whose string value is equal to the string
value of one of its c grandchildren. This can only be possible if that c
element is the only descendent of t that has any character data, as the
string value of t is all the character data from all descendents.
so this will select no nodes.


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

Current Thread