This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: position of non actual element


On Wed, Feb 27, 2002 at 07:35:45AM +0100, Rudolf Pischek wrote:

> I'm having problem with position().
> I need position of node which is not tested now, eg.
> <data>
>   <value attr="first">...</value>
>   <value attr="second">...</value>
> </data>
> 
> <!--xsl:value-of select="position(data/value[@attr = 'second'])"/-->
> of course this cannot run :-))

I don't see a way you could do this with a single XPath expression.
This works with your example, though:

1 <xsl:template match="/">
2   <xsl:apply-templates select="data/value[@attr = 'second']"/>
3 </xsl:template>
4
5 <xsl:template match="value">
6   <xsl:number count="value" from="/data"/>
7 </xsl:template>

Presumably your actual data is more complex than what you are
showing us, so you might need to use a modal template to prevent
outputting the position of every value element:

2   <xsl:apply-templates select="data/value[@attr = 'second']" mode="get-position"/>

5 <xsl:template match="value" mode="get-position">

-- 
Matt Gushee
Englewood, Colorado, USA
mgushee@havenrock.com
http://www.havenrock.com/

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]