[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: mapping (Was: Re: Re: . in for)
Hi Joerg, > Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> wrote: >> Function names are indistinguishable from element names, > [...] > Well, i realized it somewhat too late as you have seen in my > follow-up... Sure :) I'd just sent my message when yours came through. > This means you want lambda expressions. Yes please :) >> - define a map expression (rather than a map() function) > > Note that in you proposal of a mapping operator > $coordinates -> (. * 2) > the second operand actually *is* already a lambda expression. Hint: > the . is not bound to the value of the context node as it would > have been in ordinary expressions. Yes, I thought so, but I'm not an expert on this functional programming stuff so I didn't want to claim too much. I think it gives you lambda expressions in a limited set of circumstances, without adding lambda expressions as objects in the data model (which I personally can't see happening in XPath 2.0 - there's just too much else to sort out). Now you could see that as a step in the right direction, or you could see it as potentially undermining future efforts to introduce lambdas as full objects within XPath/XSLT, because it doesn't introduce a syntax that discriminates between a lambda expression and a normal expression. One possibility would be to use a keyword to indicate a lambda expression, so you'd do: LambdaExpr ::= "expression" "(" Expr ")" MapExpr ::= Expr "map" LambdaExpr and then have: $coordinates map expression (. * 2) map expression (if (position() mod 2) then . + 50 else .) We could cover up the fact we were doing this by pretending that the syntax was simply: MapExpr ::= Expr "map" "expression" "(" Expr ")" But it would mean that in XPath 3.0 then we could change Expr to include LambdaExpr. Then you could do (with a properly-defined sum() function): sum(item, expression (item * price)) It's a bit sneaky, but it might just work... Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|