Using python-lxml-2.2.3-1.1.el6.x86_64 on RHEL6.
I have a schema file using relative include statements like this:
<xs:include schemaLocation="some/relative/path/blah.xsd"/>
From this file an element tree object is created:
schematree = etree.parse(schemafile)
Then a schema object is created using:
etree.XMLSchema(schematree)
This works fine, the include statement is resolved relative to the locate of
the schema file.
Now I need to modify the schema tree object via an XSLT transformation, before
the schema object is created:
transform = etree.XSLT(...)
schematree = transform(schematree)
Now the creation of the schema object fails with the error message:
lxml.etree.XMLSchemaParseError: Element
'{http://www.w3.org/2001/XMLSchema}include': Failed to load the document
'some/relative/path/blah.xsd' for inclusion., line 3
I suppose this is caused by the fact that applying the XML transformation to
the original element tree object creates a new element tree object (or rather
_XSLTResultTree which is derived from _ElementTree), and the new object does
not have a valid docinfo property. (It is empty.) So the include file is
resolved relative to the current working directory, and not relative to the
location of the original schema XML document.
Now, is there a way to get the included file resolved relative to the location
of the original schema. I tried setting the docinfo property on the result of
the transformation, but this is not allowed.
Is there any other way?
TIA,
Markus