xsl-list
[Top] [All Lists]

[xsl] Matching the first text element in a subtree

2006-04-18 16:34:12
Hi there,

I'm attempting (using XSL 1.0 and Saxon 6.5.5) to do drop-caps by matching the first text element in the first paragraph of the second div0 in a TEI document. Where the text node is a direct child of the p tag, this works:

<xsl:template match="div0[2]/p[1]/text()[1]">

However, where another tag intervenes in the tree, this fails:

<div0>
        <p>
                <title>Blah</title> was published in...
        </p>
</div0>

Here, the first text node is the one following the title tag, which is
wrong. So what I want to do is select the first text node which is a
descendant (rather than a direct child) of the p tag. I just can't find
a way to do this. If I use this:

<xsl:template match="div0[2]/p[1]/descendant::text()[1]">

oXygen complains that "Axis in pattern must be child or attribute",
meaning presumably that only element nodes, not text nodes, can be
selected using this axis. If I use this:

<xsl:template match="div0[2]/p[1]//text()[1]">

then I get all text nodes which are the first child of their parents,
rather than only the first text node which is a descendant of the p tag.

Can anyone suggest how to go about selecting the first text node which
is a descendant of the p tag?

All help appreciated,
Martin
--
Martin Holmes
University of Victoria Humanities Computing and Media Centre
(mholmes(_at_)uvic(_dot_)ca)
Half-Baked Software, Inc.
(mholmes(_at_)halfbakedsoftware(_dot_)com)
martin(_at_)mholmes(_dot_)com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--