xsl-list
[Top] [All Lists]

Re: [xsl] Getting previous node in nodeset

2011-04-22 04:21:32
On 22/04/2011 08:24, David Carlisle wrote:
On 22/04/2011 02:28, Steve Fogel wrote:
Hi, all...

Would appreciate a suggestion:

If:

- I have a node set in the variable $nodelist
- and I have a single node in the variable $mynode
- and the node in $mynode is a member of $nodelist

then in XSLT 2.0, how do I set a variable to contain the node that is previous to $mynode in $nodelist?

For simplicity and a quick answer, you can assume that all nodes in $nodelist are siblings, but in reality, $nodelist contains<topicref>s from a DITA map, so the previous node could be a sibling, a parent, or the child of the previous sibling.

Many thanks




If I had this problem, I think I would want to take a step back: where do these two variables come from? Is there any possibility that instead of setting the variable $mynode to be one of the nodes in $nodelist, one could set a variable $myNodePosition to be the integer position of $mynode in $nodelist?

However, for the problem as stated, another option is

$nodelist[(1 to count($nodelist))[subsequence($nodelist, ., 1) is $mynode] - 1]

In 3.0 this is a classic case for some useful higher-order functions.

Michael Kay
Saxonica

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