[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Tree-walking (was: index-of() behavior)

Michael Kay mike at saxonica.com
Thu Mar 19 19:38:18 PST 2009


  Tree-walking (was: index-of() behavior)
>I'm using recursive typeswitching to mimic XSLT. 
 
The XQuery WG decided recently to add higher-order functions to the
language, and I've been wondering how this might be used to make recursive
tree-walking a less painful process.

Clearly it's easy enough to write a higher-order function that walks the
tree and applies a supplied (argument) function to each node in the tree,
which is a big step forward.

Can one go further and apply a different function to each node based on a
pattern matching (or type matching) capability?

Well, you could pass a set of functions and invoke them all, and each one
could do nothing unless the node is one that it is interested in. But that
sounds difficult to optimize.

To get close to emulating apply-templates, I think you need a function M
that maps node-names to functions T, so you pass M to your tree-walking
function W, and W when it reaches a node N calls M to obtain the function T
corresponding to the node-name of N, and then calls T. (M=mode, T=template).
I fear the result would be rather impenetrable to all but Haskell addicts.
But perhaps it could be dressed in some syntactic sugar...

Michael Kay
http://www.saxonica.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
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-2011 All Rights Reserved.