Paul Langeslag
Paul Langeslag

Reputation: 177

How do I test whether a text node intervenes between the current node and a defined preceding sibling?

In XPath/XSLT 2.0, how do I test whether a text node intervenes between the current node and a preceding sibling <lb/>, regardless whether non-text nodes intervene?

XML:

<lb/>I'd like to test whether this text exists.<someNode/><currentNode/>

Bonus question: what is the desired syntax if the <lb/> may be either a sibling of the current node or of the parent node?

Upvotes: 1

Views: 46

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167561

<xsl:if test="preceding-sibling::text() >> preceding-sibling::lb"> tests whether there is a preceding sibling text node after a preceding sibling lb element: http://xsltransform.net/6pS1zCK.

In general (if there can be more than one element or text node) I think you need to use some $sib in preceding-sibling::lb satisfies some $text in preceding-sibling::text() satisfies $sib >> $text.

Upvotes: 0

Related Questions