xsl-list
[Top] [All Lists]

Re: [xsl] limit the results of preceding in predicate

2007-02-15 09:02:17
On 2/14/07, Marc Lambrichs <marc(_dot_)lambrichs(_at_)melange-it(_dot_)nl> 
wrote:
Suppose $tail is a nodeset of 'A' nodes:
<xsl:variable name="tail" select="//A"/>
All 'A' nodes have an attribute 'property' which contains a number.

Now I want to find the first 'A' node inside $tail that has a certain
property ( in this case: the sum of all preceding  @property =
$someNumber ).

If you use the following declaration just once, there's no problem.

<xsl:variable name="test"
select="$tail[sum(preceding-sibling::A/@property) = $someNumber][1]"/>

However, if $tail is part of a recursion process and changes, how can I
make sure that the 'preceding-sibling::A' are restricted to the current
$tail nodes?

In XSLT, variable once set to a value, cannot be set to another value.
It may seem strange to someone who has experiance working with
imperative programming style (where variables can be modified). But
this behaviour of variables has many (other) benifits (you could
search the archives, if you need the answer to this).

I think the solution to your problem is - you can create a recursive
named template (which you are probably already having), and define a
parameter to it (which denotes $tail, which you are saying). When you
make a recursive call to this template, pass the modified value of
$tail.

--
Regards,
Mukul Gandhi

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