Re: [xsl] xslt 2. index-of, nodes

Subject: Re: [xsl] xslt 2. index-of, nodes
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 3 Jul 2003 12:22:30 +0100
Dave,

> Hence I need to find out, roughly
>  whether the context-item() is 1,2,3,4 etc, in
>  the sequence of all loc elements with identical hl, side and pos
> attributes.

I think that using the same method as you'd use in XSLT 1.0 would
work:

  count(preceding::loc[@hl = $context/@hl and
                       @side = $context/@side and
                       @pos = $context/@pos]) + 1

> variable name='set'
>   select='//loc[@hl=$context/@hl and @side=$context/@side and
> @pos=$context/@pos]'
>
> What's not working as I expect  is index-of($set,context-item())
>   since (I guess) it uses typed value, not the node itself?
> (Always returns 1)

That's right. The arguments to index-of() are atomised to atomic
values, so you're getting the index of the <loc> element with the same
typed value as the <loc> element you're looking at.

Of course there might be other, better, methods depending on how
you're processing the <loc> elements. For example, perhaps you could
use XSLT 2.0's grouping mechanism to process all the <loc> elements in
the group at once, and then just use position().

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread