[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XPath 2.0 - how much of XQuery should it include?


xpath sequence
Bill,

>> 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
expression:

  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
    nodes
  - 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
paths.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.