After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 335110 - XPath string "//foo/descendant::bar" doesn't parse
XPath string "//foo/descendant::bar" doesn't parse
Status: RESOLVED NOTABUG
Product: libxml2
Classification: Platform
Component: general
2.6.x
Other All
: Normal minor
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2006-03-19 12:07 UTC by david
Modified: 2007-02-21 23:10 UTC
See Also:
GNOME target: ---
GNOME version: 2.11/2.12



Description david 2006-03-19 12:07:18 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>
Comment 1 kbuchcik 2006-03-21 09:44:49 UTC
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
Comment 2 Antti Kaihola 2007-02-21 23:10:54 UTC
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?