xsl-list
[Top] [All Lists]

[xsl] determining position based on predicate

2010-10-15 12:05:36
I am attempting to find the position of an element based on a predicate. Is 
this possible.

Here is a snippet of incoming xml:
<chapter>

<tocItem startNum="38" endNum="39">
            <sublesson>
               <subtitle>Topic A</subtitle>
               <subpages>  pp. 40–41</subpages>
            </sublesson>
         </tocItem>

<!--much more like this-->
<tocItem startNum="40" endNum="41">
            <lesson>
               <lessontitle>Lesson A</lessontitle>
               <subpages>  pp. 40–41</subpages>
            </sublesson>
         </tocItem>
</chapter>

The following count statement does not seem to work. Is there a way to find a 
position based on a predicate?


<xsl:template match="chapter">

<xsl:for-each select="tocItem">
<xsl:choose>
<xsl:when position()=count(.[lesson/lessontitle='Lesson A'])-1">

<!--do some stuff and close when, choose etc.-->

I can use position()=last()-1 but the desired position is not always second to 
the last.

Terry


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>