OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] XPath 2.0 - how much of XQuery should it include?

[ Lists Home | Date Index | Thread Index ]


>> Similarly, we already have a looping statement in XSLT --
>> xsl:for-each. Most languages don't have a looping expression 
>> as well, but I recognise that it would be incredibly useful 
>> in XPath 2.0. That's why I said that there should be simple 
>> mapping operator, to handle the 80% of cases where you only 
>> need to loop over a single sequence. I've suggested something like:
>>   sequence-expression -> expression
>> for example:
>>   (1, 2, 3) -> (. + 1)
>> would give you (2, 3, 4).
> You want this (in scheme):
> (define (map func seq)
>  (if(null? seq) 
>    nil
>    (cons (func (car seq)) (map func (cdr seq)))))
> (I though XSLT had this. (Oops, it doesn't.))

Just to say a bit more about this. XPath already has some restricted
kinds of mapping expressions, the most obvious of which is the path

  node-set-expression / expression

which performs the same thing as the general map function above, or
indeed the simple mapping operator that I'm interested in, but (for
good usability reasons about the kinds of things that you want to do
when collecting nodes from a node tree):

  - is restricted to (argument and result) sequences that only hold
  - removes duplicates from the resulting sequence
  - sorts the resulting sequence into document order

Since functions aren't first-class objects in XPath, we can't pass
them around as arguments to functions (although as you're probably
aware, Dimitre Novatchev has done a lot of work on treating XSLT
templates as objects in FXSL -- see
http://www.topxml.com/xsl/articles/fp/ ).

A full functional programming language would be great, but we've been
told that we're not going to get that at this stage. That means that
we have to use expressions/operators to give a similar functionality
(hence the for expression).

Other people have suggested syntax that's closer to functional syntax:

  map expression over sequence-expression

The reason I like the infix operator is that it's easy to string
together sequences of mapping operations, just like the infix operator
for the path-mapping function enables you to build up longer location



Jeni Tennison


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS