xsl-list
[Top] [All Lists]

Re: [xsl] count Nodes with attributes until... (XSLT 1.0)

2006-06-28 02:44:06
That's nice George!

Regards,
Mukul

On 6/28/06, George Cristian Bina <george(_at_)oxygenxml(_dot_)com> wrote:
You can count the number of following siblings that have the count-me
attribute set to yes and remove the nodes to be counted after the first
node that does not have a count-me equals with yes attribute:

count(following-sibling::*[(_at_)count-me='yes'])-
count(following-sibling::*[not(@count-me='yes')][1]/following-sibling::*[(_at_)count-me='yes'])

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


news(_at_)swisslab(_dot_)de wrote:
> Hello List,
>
> I have to count a number of nodes. Each node that is to be counted has an
> attribute 'count-me="yes"' (this is a example :)). But as soon there is a
> node which does'nt have such an attribute, or has a attribute
> 'count-me="false"' this and all following nodes are not to be counted. The
> result value is dependent on the number of the node that is in the focus.
>
> Example:
> <theExampleXMLTree>
>       <Node count-me="yes"/>
>       <Node count-me="yes"/>
>       <Node count-me="yes"/>
>       <Node/>
>       <Node count-me="no"/>
>       <Node count-me="yes"/>
> </theExampleXMLTree>
>
> The value wanted is e.g. 2 when processing the first node.
>
> ...
>
> This is how I've tried it so far. The problem here is, that when processing
> the first Node I always get the value of 4 (what is quite logical to me).
>
> <xsl:template natch="Node" mode="counting_example">
>   <xsl:variable name="number" select="following-sibling::*[(_at_)count-me =
> 'yes')]"/>
> </xsl:template>
>
> I also tried:
>   <xsl:variable name="number" select="following-sibling::*[position()
> +1][(_at_)count-me = 'yes')]"/>
>
> But that just counts the next node if it has the matching attribute.
>
> Let me show what I actually want at the following tabel (using the XML shown
> above):
> NodeNr.|Value
> 1|2
> 2|1
> 3|0
> 4|0
> 5|1
> 6|0
>
> Is this possible? and how?
>
> With best regards,
> Jan

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>