W3C home > Mailing lists > Public > www-ql@w3.org > January to March 2004

Re: how to write such xquery?

From: Per Bothner <per@bothner.com>
Date: Sat, 06 Mar 2004 08:38:02 -0800
Message-ID: <4049FE6A.20906@bothner.com>
To: Per Bothner <per@bothner.com>
Cc: Xavier Franc <xfranc@online.fr>, www-ql@w3.org, Chen Yabing <iscp0054@nus.edu.sg>

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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 22 July 2006 00:10:19 GMT