Re: templates in XQuery

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 UTC