Re: [xsl] Getting previous node in nodeset

Subject: Re: [xsl] Getting previous node in nodeset
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Fri, 22 Apr 2011 11:54:59 +0530
Hi Steve,
    Probably something like following might work (not tested),

<xsl:variable name="posOfNode" as="xs:integer">
     <xsl:for-each select="$nodelist">
          <xsl:if test="is-same-node(., $mynode)">
               <xsl:value-of select="position()"/>

<xsl:variable name="result" select="$nodelist[$posOfNode - 1]"/>

I imagine, there may be a better way also to solve this problem.

On Fri, Apr 22, 2011 at 6:58 AM, Steve Fogel <STEVE.FOGEL@xxxxxxxxxx> 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
> Steve Fogel
> Information Architect, Oracle Database
> Oracle Corporation

Mukul Gandhi

Current Thread