I have an XML file which references an associated XSL file, like this:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="my-transform.xsl"?>
<my-root> .....
and I want to read it in as a org.w3c.dom.Document, applying the transform.
I'm considering reading it in, extracting the stylesheet processing-instruction using XPATH /processing-instruction('xml-stylesheet') and then loading the XSL file by hand and applying it with a Transformer.
But it seems odd that I need to do this manually - is there a neat way to read the file and apply the embedded transform automatically?
UPDATE: thanks to @raphaëλ for observing that TransformerFactory.getAssociatedStylesheet(...) will identify the xml-stylesheet value as a Source, which is pretty close. Is there anything more automatic than that?
getAssociatedStylesheet(docs.oracle.com/javase/8/docs/api/javax/xml/transform/…) to obtain theSource- raphaëλ