GNOME Bugzilla – Bug 335110
XPath string "//foo/descendant::bar" doesn't parse
Last modified: 2007-02-21 23:10:54 UTC
Please describe the problem: When using XSLT, can't use a match using //foo/descendant::bar Steps to reproduce: 1. xsltproc foo.xsl /dev/zero Actual results: mojo-jojo david% xsltproc /tmp/foo.xsl /dev/zero error xsltCompileStepPattern : 'child' or 'attribute' expected compilation error: file /tmp/foo.xsl line 3 element template xsltCompilePattern : failed to compile '//foo/descendant::bar' Expected results: no error Does this happen every time? yes Other information: minimal test case <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="//foo/descendant::bar"/> </xsl:stylesheet>
According to the grammar for patterns [1], "//foo/descendant::bar" is not a valid pattern, so the processor is correctly reporting an error. To make work what you want, use "//foo//bar" instead. [1] http://www.w3.org/TR/xslt#NT-Pattern
This is from the W3C XSLT recommendation: NOTE: The location path //para[1] does not mean the same as the location path /descendant::para[1]. The latter selects the first descendant para element; the former selects all descendant para elements that are the first para children of their parents. This leads me to assume that the correct way to match e.g. the first <para> element inside a <section> element, no matter how deep it is in the hierarchy, is: <xsl:template match="//section/descendant::para[1]"> But this doesn't work in libxml2. Maybe there's a neat work-around?