XML News from Wednesday, February 3, 2010

I spent a morning debugging a problem that I have now boiled down to this test case. The following query prints 3097:

<html>
{
let $num := count(collection("/db/quotes")/quote)
return $num
}
</html>
and this query prints 0:
<html xmlns="http://www.w3.org/1999/xhtml">
{
let $num := count(collection("/db/quotes")/quote)
return $num
}
</html>

The only difference is the default namespace declaration. In the documents being queried the quote elements are indeed in no namespace. Much to my surprise XQuery has broken the semantics of XPath 1.0 by applying default namespaces to unqualified names in path expressions. Who thought it would be a good idea to break practice with XSLT, every single XPath implementation on the planet, and years of experience and documentation? There's an argument to be made for default namespaces applying in path expressions, but the time for that argument to be made was 1998. Once the choice was made, the cost of switching was far higher than any incremental improvement you might make. Stare decisis isn't just for the supreme court.