[xquery-talk] Advancing with XQuery article

Michael Kay mike at saxonica.com
Wed Oct 1 12:25:00 PDT 2008

Good article. A few comments:

1>XQuery allows you to bind a prefix to an empty string to indicate placing
element into the default element namespace 

I don't think that's correct.

declare namespace p = "";

makes p unavailable for use. To quote: "If the URILiteral part of a
namespace declaration is a zero-length string, any existing namespace
binding for the given prefix is removed from the statically known
namespaces. "

2>If you had a system-property() function, it would be relatively easy to
XQuery function libraries made up of XQuery processor specific functions.

It wouldn't actually help much, because the function bindings would still
fail. You need a compile-time conditional, like XSLT 2.0's use-when (or some
analog to xsl:import).


Why do so many people use the "fn:" prefix, it seems totally unnecessary?

4>Note: It's been kindly pointed out to me that these functions can check
equality of
datatypes as well

I'm not sure what you mean by that, but it seems misleading. Datatypes
aren't values and can't be compared. And if you mean that deep-equal()
requires two values to have the same type, it doesn't - a decimal can still
compare equal to a double.

5>fn:not(fn:boolean(fn:compare($a, $b)))

Can't see why you would want to do this rather than using "eq". If you want
to force codepoint collation, use a third argument to compare(), or use

6>Note that this is a naive implementation of assertion (for example, even
when disabled, it still calls the test:assert function, albeit with almost
processing cost).

In Saxon there should be zero run-time cost - if($DEBUG) then ... else -
gets optimized at compile time if DEBUG has a constant value. (In fact, a
number of your examples will probably be evaluated entirely at compile time
- check by using -explain.

7>As with the local:factorial example, you have a tail recursive function.

No, the treewalker function is not tail-recursive. The recursive call is
nested inside an element constructor which is itself inside a for loop. (But
since the recursion depth is the depth of the XML tree, this doesn't


Saxon will probably optimize this to

declare function local:filter($func, $seq as item()*) as item()* {
  $seq[saxon:call($func, .)]

but I wonder why you didn't write it that way? It seems to be the common
XQuery trap of using complex FLWOR expressions where simple XPath
expressions will do.

Michael Kay

> -----Original Message-----
> From: talk-bounces at x-query.com 
> [mailto:talk-bounces at x-query.com] On Behalf Of James Fuller
> Sent: 01 October 2008 09:49
> To: Andrew Welch
> Cc: talk at x-query.com
> Subject: Re: [xquery-talk] Advancing with XQuery article
> On Wed, Oct 1, 2008 at 10:39 AM, Andrew Welch 
> <andrew.j.welch at gmail.com> wrote:
> > Clicking "register now or sign in" takes me to "webpage not 
> available"....
> >
> > Any chance you can post it elsewhere?  (having to register is lame 
> > even if it is "free")
> I have put PDF to here as well
> http://jim.fuller.name/x-advxquery-pdf.pdf
> I will put up the full package in a few days (e.g. source code) ...
> occupied with another release currently.
> hth, J
> >
> >
> > 2008/10/1 James Fuller <james.fuller.2007 at gmail.com>:
> >> Hello All,
> >>
> >> I have had my xquery article published at IBM ... I 
> thought I would 
> >> post it here
> >>
> >> 
> http://www.ibm.com/developerworks/edu/x-dw-x-advxquery.html?S_TACT=10
> >> 5AGX06&S_CMP=HP
> >>
> >> You will need to logon to IBM for this tutorial (free register).
> >>
> >> To run code samples you will need Michael Kay's excellent SAXON-SA 
> >> XQuery and XSLT processor(yes, so u need to own it or have 30 day
> >> trial) and Apache Ant (which is used to run code samples).
> >>
> >> cheers, Jim Fuller
> >> _______________________________________________
> >> talk at x-query.com
> >> http://x-query.com/mailman/listinfo/talk
> >>
> >
> >
> >
> > --
> > Andrew Welch
> > http://andrewjwelch.com
> > Kernow: http://kernowforsaxon.sf.net/
> >
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk

More information about the talk mailing list