Re: how to write such xquery?

Per Bothner wrote:

> declare function convert-node($x) {
> typeswitch ($x)
>   case matching chapter/title (: title in chapter :)
>     return <h1>{convert-children($x)}<h1>
>   case matching section/title (: title in section :)
>     return <h2>{convert-children($x)}<h2>
>   case matching title (: default for title :)
>     return <h3>{convert-children($x)}<h2>
>   ... other cases ...
>   default return convert-children($x) };
> 
> Note that this is quite compact and convenient, though it
> doesn't have the convenience of xsl:import or priorities.
> (The priority is handwired to be the order in the typeswitch.)
> One could of course add templates in addition.

Note that templates are basically overloaded functions, so
if XQuery 2.0 adds the "matching PATTERN" syntax plus overloaded
methods you have the basic template functionality.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

Received on Saturday, 6 March 2004 11:38:13 UTC