[xquery-talk] why must one have something inside {} ?

G. Ken Holman gkholman at CraneSoftwrights.com
Sat Dec 3 06:22:34 PST 2011

At 2011-12-03 08:40 -0500, David Lee wrote:
>While certainly I agree with the solution ... use this form
>    { (: comment :) () }
>Or this
>   { () (: comment :) }
>I think the question still stands as valid (although almost pointless except
>historical interest asking 'why' questions from standards bodies ..)
>Why is {} not equal to { () }
> From a syntax and readability point of view I don't see why {} can be
>equivalent to {()}  ... but it's not.

I suspect because there are many places for XPath expressions where 
the empty string does not make sense.  If "" were allowed, then this 
would be a valid expression:


... which would evaluate to nothing if the empty predicate XPath 
expression is interpreted as ().

Or this, which would also be deemed as valid and also produce nothing:

    price[. > ]

I think it is better to get an error message in such cases than to 
accept something that always does nothing and produce results 
unexpected for the user.  The absence of an XPath expression is, 
today, always considered an error because I think that when it is 
absent it really is an error.  The above two expressions are "bad" 
expressions that should be caught at compile time, rather than being 
deemed acceptable syntax because one of the valid expressions in 
XPath is to say nothing.

There are many places in XPath where an XPath expression is allowed.

I don't see why one case, and that of a comment of all things, should 
invalidate all other "bad" expression writing cases.  Think of how 
many poorly-written expressions would be considered acceptable, thus 
causing the user grief by having it execute what the user doesn't expect.

The specification is rigourous in order to account for all the places 
where expressions are used.  Special cases in specifications are 
awkward to specify and difficult to implement.

Remember that the brace brackets "{" and "}" are *not* part of XPath, 
they are part of the expression language that uses XPath.  In XSLT 
these are used in attribute value templates to wrap a valid XPath 
expression.  In XQuery these are used in attributes or in elements to 
wrap a valid XPath expression.  The braces themselves are not part of 
the XPath expression.

When you say ...

At 2011-12-03 08:40 -0500, David Lee wrote:
>Why is {} not equal to { () }

... you are mixing apples and oranges.  You are mixing the XPath 
expression language with the language that is using XPath.  What 
would you say to some other language that uses XPath with a different 
wrapping syntax?  You would have to special-case that as well.

I think XPath is very well specified to be intuitive to the user in 
99.44% of the cases ... that the user has the "burden" (as implied by 
you and jidanni) just for the one case, where an empty string is 
intuitive but not lexically allowed, seems extreme to me.

I hope this explanation is considered helpful.  I'm not criticizing 
that some people have this intuition, as I see it in the classroom 
every class ... but I think simply throwing in a special case for 
this one situation is really inappropriate.  You seem to knock my 
quoting of the specification, but I think that really is where the answer lies.

. . . . . . . . . . . . . Ken

Contact us for world-wide XML consulting and instructor-led training
Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0 http://ude.my/t37DVX
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/q/
G. Ken Holman                   mailto:gkholman at CraneSoftwrights.com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal

More information about the talk mailing list