[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: [xsl] Re: Matching the first text element in a subtree
From: Martin Holmes <mholmes@xxxxxxx>
Date: Wed, 19 Apr 2006 16:14:11 -0700

Michael Kay wrote:
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.

What a strange restriction. I wonder what the reasoning behind it is.


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])]

That works great -- it's exactly what I need. The whitespace issue isn't a problem -- I stupidly pretty-printed my example without thinking, trying to clarify the structure, but the original documents are clean.

Thanks to everyone for the helpful suggestions.

Cheers,
Martin

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