#2 parse error on xpath ""(//c)[1]"

closed-invalid
nobody
None
5
2004-12-26
2004-11-13
Oleg Paraschenko
No

XPath

(//c)[1]

considered to be incorrect. The code

(define xp (sxml:xpath "(//c)[1]"))

produces error

XPath/XPointer parser error: expected - NCName instead
of (.

production [15] says a parenthesized expression is a
PrimaryExpr
production [20] says a FilterExpr is a PrimaryExpr
optionally followed by a Predicate (which is an
Expression surrounded by
[] by production [8]
and production [19] says a FilterEXpr is a PathExpr

Discussion

  • Logged In: YES
    user_id=951535

    Production [20] FilterExpr doesn't necessary evaluate to a
    nodeset, since FilterExpr may contain no [8] Predicates
    and [15] PrimaryExpr can freely evaluate to a non-
    nodeset: say, into a boolean or a number.

    Since XPath is designed as "a language for addressing
    parts of an XML document", its production [1]
    LocationPath is used as a start production of the grammar
    to guarantee that the result is always a part of an XML
    document, i.e. a nodeset. Productions like [20] FilterExpr
    are the _internal_ productions of the XPath grammar.
    Although some of these productions are more powerful
    than [1] LocationPath, they do not necessarily _address
    parts of an XML document_.

    In SXPath, the sxml:xpath function mentioned parses the
    production [1] LocationPath and thus naturally yeilds a
    parse error for "(//c)[1]".

    If you wish to parse the more powerful production [14]
    Expr (FilterExpr is a particular case of an Expr), you
    should use a different SXPath API function,
    sxml:xpath-expr
    Anyway, you should be aware that the result of an XPath
    production [14] Expr is not necessary a nodeset. This may
    be crucial for applications like XSLT processing, e.g.
    <xsl:apply-templates select="..."/>

     
    • status: open --> closed
     
  • Logged In: YES
    user_id=534833

    Sorry for late answer. Thank you for explanations and
    pointing to "sxml:xpath-expr".

     
    • status: closed --> closed-invalid