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

Re: templates in XQuery

From: Xavier Franc <xfranc@online.fr>
Date: Mon, 08 Mar 2004 20:57:49 +0100
Message-ID: <404CD03D.50604@online.fr>
To: www-ql@w3.org

Templates seem more flexible than this "patternswitch", because
they are intrinsically modular. Also they save the job of properly
combining patterns in potentially large switches.

Anyway, although I think it would be technically excellent to
add such a feature to XQuery (and other interesting features
that are part of XSLT2, like grouping, formatting, analyze-string etc) --
I also feel that obstacles to this are more psychological or
political than technical. That would create a stronger competition
between XQ and XSLT2, and make harder to justify why there
are two different languages for more or less the same purpose.


the job

>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.
>  
>
Received on Monday, 8 March 2004 15:00:08 GMT

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