I’m trying to match all a/c elements that have a b sibling. I’ve tried:
<xsl:template match="a/b/../c">
but I get “Cannot convert the expression {..} to a pattern” from Saxon.
My XSLT/XPath skills are basic at best…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Explanation: match any
celement that is a child of anaelement that has abchild.You should also be able to use
..in a predicate:which is similar to what you were trying.
The reason you can’t use
..directly in a match pattern (i.e. outside of a predicate) is that patterns are not XPath expressions, even though they look and behave very similarly. In particular, only “downward” axes (child::,descendant::, andattribute::) are allowed directly in patterns. (The only explicit axes allowed by the spec arechild::andattribute::.descendant::is implicitly allowed via the//between pattern steps. Saxon seems to bend the rules a bit here, allowing an explicitdescendant::axis, and evendescendant-or-self::!)The reason given for the restriction on axes is that (a) other axes are rarely needed in patterns, and (b) this allows XSLT processors to be much more efficient in testing for matches.
But predicates in patterns are defined with the same syntax rules as in XPath expressions (with some restrictions in XSLT 1.0, like not allowing variable references or
current()). So you can use other axes, likeparent::, or the abbreviation...