This is what we have implemented to, but just for XPath now.
Would make a nice addition to Saxon itself I think.
From: Michael Sokolov [mailto:email@example.com]
Sent: vrijdag 10 augustus 2012 12:47
To: Mailing list for the SAXON XSLT and XQuery processor
Cc: Michael Kay
Subject: Re: [saxon] 18.104.22.168 exception with empty default namepace ("uri":local ...)
On 8/9/2012 4:27 PM, Michael Kay wrote:
Ah, I see now.
So I think it's clear that the output of toString() is intended primarily for the human user, and I therefore don't think it's unreasonable for Saxon to return a representation of the NodeTest that can only be parsed using XPath 3.0, given that this allows
us to make the namespace URI explicit.
Making toString() on expressions and related classes guarantee to return a parseable representation of the expression might be useful, but it's not currently something we attempt.
I've been spending some time on a project that translates Saxon's Expression objects into its own AbstractExpression tree, performs some rewriting, and then outputs this as serialized xquery which can be recompiled by Saxon. AbstractExpression.toString()
produces valid XQuery. I tested by passing the XQTS through it and evaluating the result using Saxon - there are a few issues with surrogates and a couple of other esoteric things I forget at the moment. If there's interest, I can make this available under
an open source license.