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

Subject: RE: [xsl] Matching the first text element in a subtree
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 19 Apr 2006 08:17:55 +0100
> 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. 

No, it means what it says. You can use "//" in a pattern, but you can't use
the descendant axis, or any axis other than "child" or "attribute". It's an
irritating restriction when you hit it, but it doesn't come up sufficiently
often to have been fixed in 2.0.

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

In 2.0:

p//text()[. is ancestor::p[1]/descendant::text()[1]]

In 1.0:

p//text()[generate-id(.) =
generate-id(ancestor::p[1]/descendant::text()[1])]

But most people, I think, end up doing the work at the apply-templates level
rather than in the match pattern.

Michael Kay
http://www.saxonica.com/

Current Thread