GNOME Bugzilla – Bug 135864
xml:base resolving relative to top element
Last modified: 2009-08-15 18:40:50 UTC
When processing nested XIncludes, the processor resolves each relative xml:base relative to the top level document. According to my reading of xml:base, a relative xml:base should resolve relative to its parent element. Here are three short example files to illustrate the problem. This is the top level document: <?xml version="1.0" encoding="utf-8"?> <book> <xi:include href="modules/chapter1.xml" parse="xml" xmlns:xi="http://www.w3.org/2003/XInclude"/> </book> This is modules/chapter1.xml: <?xml version="1.0" encoding="UTF-8"?> <chapter> <xi:include href="sections/section.xml" parse="xml" xmlns:xi="http://www.w3.org/2003/XInclude"/> </chapter> This is modules/sections/section.xml: <?xml version="1.0" encoding="utf-8"?> <section> <para> This is some text to see where I'm going. </para> </section> When I process includetop.xml with xmllint --xinclude, I get: <?xml version="1.0" encoding="utf-8"?> <book> <chapter xml:base="modules/chapter1.xml"> <section xml:base="modules/sections/section.xml"> <para> This is some text to see where I'm going. </para> </section> </chapter> </book> I would have expected the second xml:base to be "sections/section.xml" since the section element's parent has an xml:base that includes "modules". I need to resolve this so that the DocBook XSL stylesheets can properly resolve the relative locations of graphics files within an element that has xml:base. I thought it needed to merge the xml:base attributes for all of its ancestors, but the behavior of xmllint suggests it just needs to use the closest ancestor's xml:base.
According to my reading of the XInclude spec, your expectation is correct. I have coded a proposed fix, but I need to consult with Daniel before committing it. In any event, it should be resolved before the next release. Sorry for the rather lengthy time to get this bug fixed. Bill
Well, that was a lengthy consultation :-). The proposed fix grew into a new library routine to handle relative URI's, plus some additional enhancement to xinclude.c. It certainly handles your test case: bill@billsuper bug135864 $ ./xmllint --xinclude bug.xml <?xml version="1.0" encoding="utf-8"?> <book> <chapter xml:base="modules/chapter1.xml"> <section xml:base="sections/section.xml"> <para> This is some text to see where I'm going. </para> </section> </chapter> </book> The fix has been committed to CVS (xinclude.c, uri.c, include/libxml/uri.h). I would appreciate it if you could exercise it as much as possible before the next release and report back any further problems. Thanks for your patience, and my apologies for the time it has taken to resolve this. Bill
This should be closed in libxml2-2.6.11, thanks, Daniel