Ok, great. Thanks again, Mike. It would be nice for Marklogic to clarify what's going on with namespace::, since the docs at least imply that it's supported without exceptions: http://developer.marklogic.com/pubs/4.2/books/xquery.pdf
-W -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Michael Blakeley Sent: Wednesday, October 26, 2011 9:44 AM To: General MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] Is the namespace axis legit? I think it was a mistake for the W3C folks to deprecate the namespace axis. I still use it occasionally. But when I was doing something similar for the xqut test framework (https://github.com/mblakele/xqut/) I found that the namespace axis didn't work for all the cases I tested. I didn't write down the details, but there were various corner-cases that produced unexpected results. So I ended up using resolve-QName instead. let $n := <cts:element xmlns:_1="http://xyz.com/xq/my-prefix">_1:my-facet</cts:element> return xdmp:describe(resolve-QName($n/string(), $n)) => fn:QName("http://xyz.com/xq/my-prefix", "my-facet") let $n := <cts:element xmlns:_1="http://xyz.com/xq/my-prefix">_1:my-facet</cts:element> return element { resolve-QName($n/string(), $n) } { 'test' } => <_1:my-facet xmlns:_1="http://xyz.com/xq/my-prefix">test</_1:my-facet> For my use-case, this worked much better than using the namespace axis. Since resolve-QName resolves a particular string representation of a QName using a particular element context, it meshes well with the cts:element. And this technique doesn't use any deprecated features. -- Mike On 26 Oct 2011, at 08:32 , Will Thompson wrote: > Transforming some search:parse() XML output using the recursive typeswitch > pattern, I discovered that the namespace in cts:element would not copy: > > <cts:element-range-query qtextpre="My-facet:" qtextref="cts:annotation" > operator="="> > <cts:element xmlns:_1="http://xyz.com/xq/my-prefix">_1:my-facet</cts:element> > > copy-namespaces options have no effect, evidently because the namespace is > not used on any descendant nodes, so it's always dropped regardless of the > declaration. > > I got it to copy with $n/namespace::*; however, I've read several threads > suggesting that axis is actually deprecated in XQuery, and also the spec, > which seems to contradict itself: > > "XQuery does not support the namespace axis and does not represent namespace > bindings in the form of nodes. However, where other specifications such as > [XSLT 2.0 and XQuery 1.0 Serialization (Second Edition)] refer to namespace > nodes, these nodes may be synthesized from the in-scope namespaces of an > element node by interpreting each namespace binding as a namespace node." > > Is it safe to use the namespace axis now and in the future? I have seen > several elaborate workarounds for copying unused in-scope namespaces without > it, but this would be much easier. > > Thanks! > > Will > > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general > _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
