I am trying to find out the position of both my parant and grandparent from
my current node
What would be nice is <xsl:value-of select="../position()"/> and
<xsl:value-of select="../../position()"/> etc but this does not work.
I have had limited success with <xsl:value-of
select="count(../preceding-sibling::node())+1"/> for the parent, but I
cannot seem to get anything working for grandparent.
Thanks from the comfort of my padded cell.
I don't know if this will help your particular case, but...
In using XSLT to render an article-style document with nested sections,
I wanted section titles of the form, e.g., "2.3 Title". Here the 2.3 is
based on the position of the current heading and subheading, as is
typical of formal reports.
My source document has an <article> element as its root. Within that, it
can have arbitrarily nested <section> elements, with the top level
representing major headings, the next level down subheadings, etc. I
used the following idea to get hold of the section numbers, which are
essentially the positions of the current element at each heading level.
This example is for a subheading, as in the "2.3 Title" above.
<xsl:variable name='secnum'>
<xsl:number count='/article/section'/>
</xsl:variable>
<xsl:variable name='subsecnum'>
<xsl:number count='/article/section/section'
from='/article/section'/>
</xsl:variable>
Hope it helps,
Chris
position of a node is always relative to a node list. Which node list you
want the position to be relative to ? The sibling elements of the same
name? All the sibling elements, whatever their name? All the sibling nodes?
That's the reason why such a function doesn't exist in XPath.
> I have had limited success with <xsl:value-of
> select="count(../preceding-sibling::node())+1"/> for the parent,
That's the way to do it.
> but I cannot seem to get anything working for grandparent.
count(../../preceding-sibling::node()) + 1
fu2 ctx
Tom.