[xsl] Matching only text nodes with certain (complicated) properties
Subject: [xsl] Matching only text nodes with certain (complicated) properties|
From: "David B?rgin" <david.buergin@xxxxxxxxxxxxx>
Date: Fri, 09 Jan 2009 18:07:47 +0100
There's this matching problem I cannot solve:
In one template of my XSL stylesheet I'd like to match a text node with
certain properties. Namely, the template should match for any text node
where the nearest preceding non-empty text node is farther away than (=
comes before) the nearest preceding <pb/> (page-break milestone element).
I'll give you some context on what I'm trying to do: I have a TEI P5
document (http://www.tei-c.org/), where page breaks are indicated by
milestone elements of the form <pb n="[number]"/>. These can occur anywhere.
From this TEI document, I'd like to generate XHTML with the <pb/> elements,
of course, removed, but now represented as a <span> containing the page
number at the very beginning of the next text node. (In the browser
presentation, this <span> would then be floated outside regular flow --
using CSS -- as page indicators in the margin of the page ... is what I'd
planned to do, at least)
Here's an example fragment from the source document (here with a list inside
before a vowel.
<item n="a">The <mentioned>thingy</mentioned>
I'm trying to match nodes such as "The " in the last line of the example,
where the nearest preceding text node "before a vowel." is farther away than
the nearest preceding <pb/>, "<pb n="26"/>". Before "The " I would then
insert my <span>, "<span>Page <xsl:value-of select="[select preceding
pb/@n]/></span>". In this way, the page break information would effectively
be moved to right before the next following text node, everywhere.
As far as I understand it, the main problem is that the expression I have to
construct for matching can't rely simply on the preceding:: or ancestor::
axes since the <pb/> can really appear anywhere in the tree.
I found related questions in the archive but nothing that would help, so I
appreciate any help very much.