This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Indexing Tree Elements
- To: xsl-list at mulberrytech dot com
- Subject: Re: Indexing Tree Elements
- From: Lee Goddard <lee dot goddard at bigfoot dot com>
- Date: Fri, 07 Jul 2000 15:00:29 +0100
- Organization: School of Cognitive Science, University of Sussex
- References: <93CB64052F94D211BC5D0010A800133101FDEF5F@wwmess3.bra01.icl.co.uk>
- Reply-To: xsl-list at mulberrytech dot com
Kay Michael wrote:
>
> > I have a template that is called for all instances of an element;
> > is it possible that it may compare its attributes with the attributes
> > of the previous document-tree node of the same level? Is it possible
> > to index elements in such a manner?
>
> Yes (in XSLT) (well almost).
>
> <xsl:if test="@value=preceding-sibling::*[1]/@value">
>
> does roughly what you want. The only caveat is that the "previous node on
> the same level" must be a sibling, not a cousin. If you want to test against
> an n-th cousin for any value of n, use
> preceding::*[count(ancestor::*)=$depth][1] where $depth is initialized to
> count(ancestor::*) for the context node. And be patient while it executes.
>
> I'm not sure what you mean by "indexing elements".
>
> Mike Kay
Thanks for your help, Mike. By 'indexing' I just meant something like:
if (node[$i] == node[$i-1]) then....
BTW, are you the Mike Kay of the fabulous book I've just bought?
If so, thanks for writing!
--
Lee Goddard <l.goddard@sussex>
Research Centre for Cognitive Science,
University of Sussex, Brighton UK
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list