[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Templates in XQuery

William Candillon wcandillon at gmail.com
Mon Sep 6 12:11:55 PDT 2010


  Templates in XQuery
Hi,

We tried to capture the solution proposed by John as an xquery
design pattern and came up with the translator pattern (see:
http://www.balisage.net/Proceedings/vol5/html/Candillon01/BalisageVol5-Candillon01.html#pm).

The code sample of this pattern is available at http://patterns.28msec.com.
Examples can be executed with Zorba or online at http://try.zorba-xquery.com.

Best regards,

William

On Mon, Sep 6, 2010 at 10:58 AM, John Snelson
<http://x-query.com/mailman/listinfo/talk> wrote:
> On 05/09/10 12:26, Brett Zamir wrote:
>>
>>   On 9/5/2010 5:16 PM, Martin Probst wrote:
>>>>>>
>>>>>> I wouldn't agree. To me, XQuery is an XML aggregation language. I
>>>>>> never do any significant XML transformation work using XQuery.
>>>>>
>>>>> Outside of the important omission of templates or the handful of
>>>>> features
>>>>> from XSL which have no equivalents in XQuery, what transformation
>>>>> feature of
>>>>> XSL cannot be expressed in XQuery and more succinctly so?
>>>>
>>>> That's enough isn't it?  :)  The template processing model is the
>>>> killer feature, the thing that makes XSLT the best at transforming
>>>> XML.
>>>
>>> That's my perspective as well. It might not seem much to you, but
>>> templates make all the difference in the programming model. As I said,
>>> to me XSLT is a set of rules that are applied as
>>> filters/transformation rules on a tree structure. That's a major
>>> difference from XQuery where I go out and point the interpreter at
>>> certain XML parts I'd like to find, both in mental model and in
>>> implementation, I think (not ever having implemented an XSLT processor
>>> though).
>>
>> The use cases are simply:
>> 1) Make it possible for the many people who already prefer the shorter
>> and visually contrastive XQuery syntax to be able to do so for their
>> whole document templating needs (i.e., for cases when they formerly
>> would have needed to use the XSL syntax, let them use the same XSL
>> engine they used before but which now might support XQuery+templates as
>> an alternative).
>> 2) Provide another option to XSL users not yet familiar with XQuery
>> syntax but who might like to learn something which might make them more
>> productive in their work by taking advantage of the shorter and visually
>> contrastive XQuery syntax.
>
> I've given plenty of thought in the past to adding XSLT-like templating
> facilities to XQuery - even going so far as to implement some experimental
> syntax for it in XQilla. The trouble is, XSLT's XML syntax has allowed every
> instruction to be given a large number of options as attributes or
> sub-elements, and that syntax is very hard to then translate into a grammar
> like XQuery's. So I no longer believe that adding grammar for XSLT
> compatible templates definitions to XQuery is something worth doing.
>
> Of course, just adding stylesheet import and apply-templates to XQuery is
> probably feasible, and hopefully that will be done at some point in the
> future.
>
> However, recently I've been considering implementing a templating framework
> in XQuery. With XQuery 1.1's higher order functions facility, it would be
> simple enough to build - for instance, what would people think about
> something like this:
>
> let $stylesheet := stylesheet((
>  template(function($n) { $n instance of element(foo) },
>    function($n) { <new_foo>{ apply-templates($n/*) }</new_foo> }),
>
>  template(function($n) { exists($n/self::bar/parent::foo) },
>    function($n) { () })
> ))
> return apply-templates(doc("mydoc.xml"), $stylesheet)
>
> I've got plenty of details to think through, but a simple structure of
> predicate functions and action functions, along with an apply-templates()
> function that handles it could meet the needs of anyone transforming XML in
> XQuery.
>
> John
>
> --
> John Snelson, Senior Engineer                  http://twitter.com/jpcs
> MarkLogic Corporation                         http://www.marklogic.com
> _______________________________________________
> http://x-query.com/mailman/listinfo/talk
> http://x-query.com/mailman/listinfo/talk
>



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.