> > If that's the case (and it's an XSLT sheet) the answer is to use the
> >preceding:: axis.
> Why yes, that does it! Many thanks.
My posting has brought a couple of of-list queries that suggest that some
TEI-ers hadn't realised the usefulness of the preceding:: and following::
axes for handling milestone type elements such as <pb>s. So to generalise a
little and add one possibly useful extra hint:
At any given point in XSLT processing you can get the previous or
following <pb> via
If you have, say, <pb>s from more than one edition, you can extend this to
locate a specific edition's markup:
NB the sequence of the square bracketed bits is important.
The extra hint (which is what the off-list enquirers wanted to know) is a
way of locating (only those) nodes that occur between two milestones. E.g.
you have a text with footnotes or critiical apparatus, which you want to
render page by (print edition) page, placing the footnotes or apparatus at
the foot of each page as you go:
First, near the top of your sheet create what XSLT calls a key:
<xsl:key name="fnotes" match="//note[@place='foot']"
This looks frightening, but that's mainly the rebarbative syntax. The real
problem is that the xslt element "key" is badly named. Along with its
associated lookup function, it ought to have been called "index", but that
name was already taken, so the XSLT specifiers called it "key". Which meant
they had to think up another word to specify what would otherwise have been
the "key" to the index, and they settled for "use". Not very good, but we're
stuck with it now.
So the 'match' attribute selects the items we want to index for later
retrieval (here: all nodes of type <note place="foot">). and the 'use'
attribute states the key (in the ordinary, non-XSLT-mangled sense of that
term) we want to use to retrieve them (here: the value of the n attribute on
the immediately preceding <pb>)
Having created our 'key' named 'fnotes" we can now get the set of <note
place="foot"> nodes that occur on a given print page simply by passing the
value of the n attribute on that page's opening <pb> to the key() function.
So, as we transform the document, we hit a <pb> and want to render the
footnotes on the page it terminates:
1) Get the n value of the preceding <pb> into a variable
<xsl:variable name="prevpageno" select="preceding::pb[@ed='OUP']/@n"/>
2) Pass that variable into the key() function, which takes two parameters,
the name of the (XSLT-speak) key we defined earlier and the index value of
the item we want to look up (.i.e. the "key" in ordinary usage). This gives
us precisely what we want, the set of all the footnote nodes on the page
just ended, and we can iterate over it, doing whatever we like with each
note (here, we output the note number followed by a space and the note
content, all wrapped in a <p>)
<xsl:value-of select="@n"/><xsl:text> </xsl:text>
Assuming keys are well-implemented in your XSLT processor (as they are in
all recent ones) you can use this technique to render end-of-page footnotes
in real time even where the text has several hundred pages and thousands of
notes or <app>s
You can see this in action at
where this technique is used for rendering footnotes in the front matter and
variant apparatus in the body text. Additionally, the TOC is created in a
way analogous to the solution of Jeremy's original TOC problem. Rather than
pointing to the actual div that houses each segment of text, the TOC links
point to (and retrieve starting from) the <pb> preceding that div. This was
done to meet user requests that the on-line TOC should parallel the print
edition counterpart by taking the reader to the start of page on which the
material concerned starts, even if the referenced section actually begins
Apologies to everyone who didn't want to know all this: and if anyone who
did would like to explore things further, I am glad to do so off-list.
The Anglo-Norman Dictionary http://www.anglo-norman.net/