Re: how to write such xquery?

Per Bothner <[email protected]>
Newsgroups gmane.comp.web.query-languages
Message-ID <[email protected]>
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
[email protected]   http://per.bothner.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.