[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Getting previous node in nodeset

Subject: Re: Getting previous node in nodeset
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 22 Apr 2011 06:42:08 -0700
Re:  Getting previous node in nodeset
And, of course, a solution which doesn't use subsequence() :

  for $i in (1 to count($nodelist))
    return $nodelist[$i][$nodelist[$i +1] is $mynode]


--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
Facts do not cease to exist because they are ignored.




On Fri, Apr 22, 2011 at 3:18 AM, Oliver Hallam <oliver@xxxxxxxxxxx> wrote:
> A slightly neater formulation of this is
>
> $nodelist[subsequence($nodelist,position() + 1,1) is $mynode]
>
> If you know your nodelist is in document order, then the following would
> also work:
>
> $nodelist[. << $mynode][last()]
>
>
>
> Oliver Hallam
>
>
> On 22/04/2011 10:21, Michael Kay wrote:
>>
>> 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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.