xsl-list
[Top] [All Lists]

Re: [xsl] Count previous-siblings w/same attribute value up to attribute value - 1 possible?

2011-12-12 19:59:43
On Mon, 2011-12-12 at 16:54 -0800, Lou Argyres wrote:
[...]
Is there an XPATH-2 select that can count preceding-siblings up to the
first preceding @level = $lvl-1?

 <xsl:variable name="lvl" select="@level"/>

so, you could also say,
  <xsl:variable name="upto"
    select="preceding-sibling::section[@level eq $lvl - 1]" />

The preceding sections you don't want are then
   <xsl:variable name="not-these-ones-please"
    select="($upto | $upto/preceding-sibling::section)" />

and so you now want
    preceding-sibling::section except $not-these-ones-please
which is in fact an XPath 2 expression.

Any (negligible) performance penalty for using variables is
insignificant in most cases compared to the time taken for a human to
understand the resulting expression :-)

There are lots of other ways to solve this question, of course.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/


--~------------------------------------------------------------------
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>
--~--