Re: [xsl] Count with embedded child elements

Subject: Re: [xsl] Count with embedded child elements
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sun, 8 Dec 2002 11:08:48 -0800 (PST)
"Bruce Dailey" <bruce@xxxxxxxxxxxx> wrote in message
news:000001c29ecc$614257d0$0fcbfea9@xxxxxxxxxxx
> I have an XML file like this
> 
> <tu>
> <tuv>
> <seg>Y<ut>X</ut>Y</seg>
> </tuv>
> </tu>
> 
> <tu>
> <tuv>
> <seg>X<ut>X</ut>X</seg>
> </tuv>
> </tu>
> 
> I am trying to count the occurrence of a parameter I am passing in
> "SearchText", e.g. "X" per TU. So for the above I want 1 returned,
but I
> am getting 2 returned using the syntax below: (because 2 text nodes
in
> the second <tu> have X in it, I think). 
> 
> <xsl:value-of select="count(//tu/tuv/seg/text() [contains (.,
> $SearchText)])"/>
> 
> So, in other words, I want to count the number of <tu>s that have the
> search term in the <seg> element but I want to ignore the text in the
> <ut> element.
> 
> Can someone help me out with the correct syntax.
> 
> I think my current syntax deals with ignoring the <ut> element but
> doesn't deal with the multiple text nodes in the <seg> element.


Use:

count(//tu/tuv/seg[contains (text() , $SearchText)])



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL



__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread