[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?
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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|