Re: [xsl] the count function

Subject: Re: [xsl] the count function
From: "Michael Kay michaelkay90@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 2 Oct 2026 15:10:24 -0000
When you combine two node-sets using "or", you don't get the union of the two
node-sets. "Or" is a boolean operator, it gets the effective boolean value of
both operands (true if the node-set is non-empty) and combines them to form a
single boolean; count is 1 because this is a single boolean.

You could use the ",' or "|" operator to combine the node-sets, but adding
their sizes is simpler.

Michael Kay

> On 2 Oct 2026, at 16:04, Trevor Nicholls trevor@xxxxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> XSL 2
>
> I've clearly got a fundamental blindspot with the count function.
>
> In a nutshell, I'm trying to figure out how deeply nested a certain
> element is.
>
> I'm finding that this construct:
>
> \xA0 \xA0 <xsl:value-of select="my:repeat-string('\xA0 \xA0 ',
count(ancestor::li or
> ancestor::step))" />
>
> is always producing the same output no matter how many ancestor lists
> there are
>
> It turns out that "count(ancestor::li or ancestor::step)" always
> evaluates to 1 even when there are no ancestors at all
>
> I've "corrected" my stylesheet so that it uses
>
> \xA0 \xA0 <xsl:value-of select="my:repeat-string('\xA0 \xA0 ',
count(ancestor::li) +
> count(ancestor::step))" />
>
> which works exactly as I'd expect.
>
> Why doesn't the single count(a or b) give the same result as count(a) +
> count(b)?
>
> cheers
> T
>
> \xA0

Current Thread