Subject: RE: Truncated text string, relative to child node
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 1 Jul 2008 23:18:08 +0100
|
> I have an XML file like this:
>
> <a> lorem ipsum text ... lorem ipsum <b> dolor </b> lorem ipsum ...
> lorem ipsum </a>
>
> I want to create a string of the five words from <a> right
> before the <b> tag, and a string of the five words
> immediately after <b>. All I can do is create strings from
> the beginning or the end of the <a> tag, but basically I want
> the text in the middle, relative to the child <b> node.
In 2.0, assuming the <a> element is the context node, the two sequences are
given by
subsequence(tokenize(b/following-sibling::text(), '\s'), 1, 5)
and
reverse(subsequence(reverse(tokenize(b/preceding-sibling::text(), '\s')), 1,
5))
In 1.0, you'll have to be prepared for something rather more verbose.
Michael Kay
http://www.saxonica.com/
|