This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: outputting the "position()" of parent
Justin Friedl wrote:
>
> How do I output the posistion of the parent. I can output the position of
> the current node like this:
> <xsl:value-of select="position()"/>
>
> So I thought I could do this:
> <xsl:value-of select="../position()"/>
> but it doesn't work.... any suggestions?
>
David Carlisle (whom I trust is home by now!) came up with the solution
to this:
xml:
<?xml version="1.0"?>
<root>
<a></a>
<a></a>
<a></a>
<a></a>
<a><b/></a>
<a></a>
<a></a>
</root>
xsl:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="b">
<result>
<xsl:text>b's parent is in position </xsl:text>
<xsl:value-of select="count(../preceding-sibling::*)+1" />
</result>
</xsl:template>
</xsl:stylesheet>
result (saxon):
<?xml version="1.0" encoding="utf-8" ?><result>b's parent is in
position 5</result>
Francis.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list