[xquery-talk] Tree-walking (was: index-of() behavior)
Florent Georges
lists at fgeorges.org
Thu Mar 19 20:38:37 PST 2009
Michael Kay wrote:
> 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).
Very interesting. Except that I would define M as mapping a node (not a node name) to functions, to emulate match patterns. But I guess a general, user-defined function to map from nodes to functions would be less than optimal. I guess I am too much XSLT-oriented, but a set of pairs of match patterns (as defined by XSLT) and function objects sounds reasonable to me:
M1 := (("pattern1", T1),
("pattern2", T2),
("pattern3", T3),
...)
M2 := (("pattern-a", Ta),
("pattern-b", Tb),
("pattern-c", Tc),
...)
One obvious advantage of what you describe is that W is not fixed, and could be defined by the user or by a library, and be reused, instead of having to write it again and again as in XSLT.
I thought a few weeks ago that it would be interesting to expose patterns as first-class objects, even in XSLT. It seems this would be an interesting application.
Regards,
--
Florent Georges
http://www.fgeorges.org/
More information about the talk
mailing list