Re: using ancestorChildNumber in VBScript

Subject: Re: using ancestorChildNumber in VBScript
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 21 Nov 2000 14:47:23 +0000

> As I said, that worked fine. ancestorChildNumber would back up the
> tree until it got to "Holding" and return the index of that node
> relative to its parent. I subtracted 1 because I wanted the index to
> be zero-based. Trying to do things the new way, I can't get the
> SymbolHref function to work.

As Mike said, you don't need to use scripting to get this information.
XPath is designed to enable you to navigate the DOM and find things
out about it. You want to know the index of the current node's (the
Symbol element's) parent 'Holding' element within its parent. The
first Holding element should be numbered 0, the second 1 and so on.

You can get this number by counting how many Holding elements occur
before the one you're looking at; in other words, how many preceding
siblings it has that are also Holding elements.  The first Holding
element won't have any preceding sibling, the second 1 and so on.

To get to the parent Holding element, you can use:


or, shorter and probably more readily optimisable:


You can get a list of its preceding siblings using the
preceding-sibling axis:


You can count nodes using the count() function:


So within your XSLT, you could use something like:

   <xsl:attribute name="href">
      <xsl:value-of select="count(../preceding-sibling::Holding)" />
   <xsl:value-of select="." />


<a href="DetailScreen.asp?idx={count(../preceding-sibling::Holding)}">
   <xsl:value-of select="." />

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread