I write a book database application in java. The books stored in XML format. Every book a XML. The books can contains short stories and a short story can be a XML. In that case the book look like:
<?xml version="1.0" encoding="UTF-8"?>
...
<book>
<content>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="shortStory.xml"/>
</content>
</book>
Because the user can upload only one xml, and it can be the "book.xml" wihtout the "shortStory.xml" (the shortStory.xml always uploaded before) I need to do the XSLT Transform without xinclude. (et case the two file is not the same path)
But after the upload (in other usecase) I need to do the XSLT transform with the XInclude (the two file is the same path)
Every solution what use the Xinclude set the System Property before get a instance from Transformerfactory:
System.setProperty(
"org.apache.xerces.xni.parser.XMLParserConfiguration",
"org.apache.xerces.parsers.XIncludeParserConfiguration");
Or use DocumentBuilderFactory.setXIncludeAware().
I'd like two javax.xml.transform.Transformer one set up use the xinclude and one without. Or one transformert but a simple method for javax.xml.transform.stream.StreamSource to turn on/ot the xinclude.
thanx
EDIT
Try out Martin Honnen's solution, but there was problem with the transform, so I change the SAXreader to Documentbuilder:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setXIncludeAware(true);
DocumentBuilder docBuilder = factory.newDocumentBuilder();
Document doc = docBuilder.parse(input);
Source source = new DOMSource(doc);
...
transformer.transform(source, result);