xsl-list
[Top] [All Lists]

RE: selecting the nearest preceding sibling

2003-05-13 06:40:42

De : Mukul [mailto:mukulw3(_at_)yahoo(_dot_)com]
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



<Prev in Thread] Current Thread [Next in Thread>