Re: [xsl] Matching the first text element in a subtree

Subject: Re: [xsl] Matching the first text element in a subtree
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Wed, 19 Apr 2006 02:37:15 +0200
Martin Holmes wrote:
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,

Well, unless you strip whitespace generously, the first text node would be the whitespace just after the <p>.

 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.

Try <xsl:template match="(div0[2]/p[1]//text())[1]"> note the additional parenthesis (beware, untested). Be sure to combine this with proper whitespace stripping.

J.Pietschmann

Current Thread