Following-or-end in xslt/xpath?



XPath Axes contain the directive following:: to obtain the set of all following nodes.


Given for instance the following file:



<?xml version="1.0" encoding="UTF-8"?>
<foo>
<a/>
<b/> <!-- access 1 -->
<a/>
<ca/>
<a/>
<b/>
<a/>
<a/>
<cb/>
<b/> <!-- access 2 -->
</foo>


One can for instance use following::a/preceding::b[1] to access access 1 given <ca>. In other words one wish to access:



the "last" <b> before the next <a>.



If the current node is however <cb>, that trick doesn't work anymore, since there is no following::a. Is there a following-or-end directive (or something equivalent) that in that case returns the last tag (</foo>), such that access 2 can be obtained from <cb/>?


Such following-or-next should be read as:



The next <a> or the end of the file in case this doesn't exist.



No comments:

Post a Comment