RE: [xsl] selecting the nearest preceding sibling

Subject: RE: [xsl] selecting the nearest preceding sibling
From: David Neary <David@xxxxxxxxx>
Date: Tue, 13 May 2003 15:40:42 +0200
De : Mukul [mailto:mukulw3@xxxxxxxxx]
> My XML file is below

[snip]

> I want to write **a XPATH expression which will select
> the nearest preceding sibling , which contains a
> particular element ( <a> in this example) ** . I do
> not want preceding sibling which do not contain the
> <a> tag (also the tag <a> should be nearest to the
> context node)
> 
> for e.g. if the context node is node 5 , the XPATH
> expression which will select node 3(because it
> contains element <a>) or for e.g. if the context node
> is node 2 , the XPATH expression will select node
> 1(because it contains element <a>)

OK - the node set of all the preceding siblings which 
fit the criterium is given by 

preceding-sibling::tag[a]

The nearest preceding sibling fitting the criterium is 
the last one in that nodeset (the nodes are always in 
document order)... that is, 

preceding-sibling::tag[a and last()]

Hope this works,

Cheers,
Dave.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread