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

Re: counting elements with values that match other el

Subject: Re: counting elements with values that match other element values
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 18 May 2006 14:11:16 +0100
c count
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 
   <c>3</c>
   <c>5</c>
   <c>8</c>
   <c>7</c>

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 )
is
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.


David

________________________________________________________________________
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:
http://www.star.net.uk
________________________________________________________________________

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.