Martijn Faassen wrote:
Stefan Behnel wrote:
Anyone annoyed by the fact that RNG grammars need a fixed starting point? That you can't just validate some subtree that you're interested in?
Well, here we go.
Cool feature!
yup! :)
Relocatable is a bit of a technical sounding word; I wonder whether we can come up with a better name.
Would be nice. Sounds too long and clumsy, I know.
Is this XSLT stylesheet of your own devising or did this come from somewhere else? How robust is this in the face of namespaces, Relax NG schemas that consist of multiple files, etc?
I wrote it myself. There are actually loads of ways of writing it that all do more or less the same. Multiple files are obviously a problem if the <start> tag is not in the top level one (the one that is transformed), so it can't be replaced. Namespaces are not a problem for the stylesheet. I have found a problem, though, that may (or may not) be related to namespaces. It's both in the trunk and my branch (I'm always happy when I can say that) and is pretty weird. All test cases that I could come up with so far work perfectly well, but I have one RNG (not even that long, but much too long for a test case) that fails being read by the RelaxNG class after transformation. libxml2 writes out the error message "(none) is empty", which is obviously true :), but "(none)" here refers to the RNG tree, so it may mean that libxml's xmlRelaxNGCleanupTree function (which is called on the RNG tree before transforming it into a validator) throws away the entire tree for some reason. May or may not be a namespace issue. When you serialize the result tree and then parse it again, everything works perfectly well, so maybe running the XSLT somehow corrupts the internal representation of the tree. Anyway, this is in no way related to the implementation of RRNG. Maybe it's even a bug in libxslt or something.
I also wonder whether we could make the API such that you don't have to copy stylesheets yourself, instead having this happen for you on the fly when you choose to validate a part. This though may require a bit of caching that the explicit form doesn't need.
Hmm, well, you could do that using either XPath or XSLT. You extract the name of the element where you are supposed to start and as long as it only appears once in the RNG you can find it and restructure the RNG to start at that point. S(implified)RNG should be able to assure that this is possible, but I don't think libxml2 can handle SRNG, so there are some caveats. Having SRNG available would solve a lot of problems, though (like the RNG module import problem above). BTW, I considered merging RRNG into the RelaxNG but I don't think it makes sense since RRNG has the additional overhead of requiring a (non-modifiable) copy of the normal XML tree in memory, so that's bad for the common case without relocation. Stefan