RE: [xsl] RE: For expressions and / operator in XPath 2.0

Subject: RE: [xsl] RE: For expressions and / operator in XPath 2.0
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Thu, 3 Jan 2002 13:04:04 -0000
> And introducing keywords obviously causes problems - having to put a
> colon in front of element names that could be keywords is really ugly,
> in my opinion. I also think that it will encourage newcomers to
> (wrongly) think that you need to have a : in front of all unprefixed
> QNames, or that :for is a valid QName.

Actually, the XPath 2.0 grammar is unambiguous without any reserved words.
The option of a leading colon on element names is there only for
compatibility with XQuery, which does have reserved words. This isn't
particularly well explained, and might not be the final word on the
subject...
>
> But don't you have reserved-word parsing problems all over the place
> anyway? I'd prefer an operator (e.g. "->"), but getting rid of the
> range variables would be a step in the right direction, in my opinion.

Basically, binary operators (and, or, etc) are recognized in the same way as
XPath 1.0, by virtue of the lexical token that precedes them. Function names
are recognized by a following "(", axis names by a following "::"; "if" by a
following "("; "for", "some", and "every" by a following "$". So keywords
are disambiguated from element names by a single-token lookahead.
>
> One advantage of an operator for the for expression is that it would
> allow you to 'pipeline' sequences through a series of operations more
> easily (which is one of the advantages of the location path syntax,
> especially now that function calls are allowed in general steps).
>
> Say you had a sequence of numbers (conceptually coordinate pairs). You
> could do a 'scale' operation by multiplying the pairs by 2:
>
>   $coordinates -> (. * 2)
>
> and then do a 'move' operation by adding 50 to the odd numbers:
>
>   $coordinates -> (. * 2) -> (if (position() mod 2) then . +
> 50 else .)
>

Looks quite nice to me: no harm in putting it forward. But expect
resistance - people get very emotional about syntax.

[Parochial question: does this example have something to do with the new
algorithm for British vehicle registrations?]

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread