[XQZone General] XQuery Template Engine
Darin McBeath
ddmcbeath at yahoo.com
Fri Jun 3 08:44:51 PDT 2005
You can make the following change to test.xqy and I
believe your example will work.
Change
case $e as element()
return
element {$e/name()} ...
To
case $e as element()
return
element {name($e)} ...
In your original example, you were calling the
fn:name() with no parameters ... it defaults to the
context node ... which is evidently different between
Saxon and MarkLogic for this particular query. At
least, that would be my guess.
Darin.
--- Raffaele Sena <raff at aromatic.org> wrote:
>
> After more than a year spent tinkering with XQuery
> and CIS (though not too
> much lately ): I am still trying to get to my
> ultimate goal: run a full dynamic
> website powered by XQuery and nothing else.
>
> One of the main obstacles is the lack of a
> templating system that allows
> me to quickly generate pages with a common look and
> feel. Last year I come
> up with something very basic (you can see it in
> action here:
> http://xq.aromatic.org/) that basically allowed me
> to use XQuery to create
> the page content (still using HTML tags) but have a
> common method to build
> the page skeleton. Good enough for simple pages
> but...
>
> Recently I was looking at Tapestry (one of the many
> Jakarta projects,
> possibly the successor of Struts) and, even if I
> think it's still too
> complicated for my taste I did like one thing:
> Tapestry template pages are
> regular XML (XHTML) pages.
>
> The basic idea behind it is that XHTML tags can be
> "marked up" with
> special attributes that identify which one will
> receive what application
> data (plus a lot of other information to do
> validation and more fancy
> stuff).
>
> The major benefit of this approach is that template
> pages can be edited by
> any standard HTML editor and can contain placeholder
> text or elements that
> will really show how the final page looks like (then
> the placeholder text
> and elements are replaced by the real data by the
> template engine).
>
> Since XHTML pages are valid XML pages they can be
> stored in an XML
> repository and processed using XQuery. The template
> engine can be an
> XQuery method that, given in input a document to be
> used as a template and
> a list of nodes representing the result of a query,
> can merge them and
> generate in output a document that is the input
> document where the
> "marked" tags are filled or substituted by the query
> result data.
>
> It seems pretty easy, so I tried: I wrote a very
> simple recursive function
> that given a root node scan the document, looks for
> special attributes on
> element nodes and if found matches them up with the
> content of a
> corresponding entry in a value list.
>
> There are more features to be added (better support
> for lists, so I can
> generate HTML ol/ul lists and/or table rows, some
> support for forms, maybe
> form validation, etc.) but this is a good start.
>
> You can see my attempt here:
> http://xq.aromatic.org/xqt/ but...
>
> Yes, there is a but!
>
> I tested the initial implementation on Saxon (8.4)
> and it worked fine.
> I converted the code to run under CIS (Saxon
> implements the latest and
> greatest XQuery specs) and... it doesn't work.
>
> For some reason it gets stuck thinking that the
> first element in my
> template document (html) is not a node. But if I
> print the node type it
> says it's an element node. So, what am I doing wrong
> ? :(
>
> Also, how do you think this approach performs ? Can
> you suggest
> optimizations ? (today I read Jason's reply about
> the use of
> xdmp:node-replace and I thought I could use it to
> optimize the
> parameter/value substituion: I can probably use a
> FLWOR expression to list
> the element containing an xqt:id attribute and only
> replace those nodes
> instead of having to parse the full template node by
> node. On the other
> side this version is 100% XQuery).
>
> Have other people on the list tried something
> similar ? Are other people
> interested in something like this ? Do you have any
> suggestion on how to
> implement some features or what would you like to
> see ?
>
> ...but first, please help me make this work on CIS
> :)
>
> -- Raffaele
>
>
> _______________________________________________
> General mailing list
> General at xqzone.marklogic.com
> http://xqzone.com/mailman/listinfo/general
>
More information about the General
mailing list