RE: [xsl] finding postion from value of attribute

Subject: RE: [xsl] finding postion from value of attribute
From: Flemming Jønsson <flj@xxxxxxxxxxxxx>
Date: Tue, 21 Oct 2003 13:46:39 +0200
> I have the following xml input and would like to identify the 
> position 
> of the <answer/> element with the 'correct' attribute within the 
> <question/> context and output it as as an integer ( in this case 3).
> <question>
>     <answer/>
>     <answer/>
>     <answer eval="correct">
>     <answer/>
> </question>
> Any suggestions much appreciated

I don't know whether this is too simple, but I think this could work (not tested)

<xsl:template match="answer" name="answer">
  <xsl:if test="@eval='correct'">
    <xsl:value-of select="position()"/>. <xsl:value-of select="@eval"/>

This outputs the position of the answers which are correct like this:
3. correct

You can call it like this
<xsl:apply-templates select="//answer"/> 
from your main template.


 XSL-List info and archive:

Current Thread