Thursday, April 14, 2005

Loading an XSL Stylesheet in Java

Just a friendly reminder that if you are using an XSL Stylesheet which contains xsl:include elements that are relative to the including stylesheet and you wish to load it as a javax.xml.transform.stream.StreamSource, you should not load it using the StreamSource constructor that takes as a java.io.Reader or java.io.InputStream. You should load it using the File or SystemId (URL) constructor.

The reason is, that if you load it as a Reader or an InputStream object, the object in charge of resolving the included elements does not know relative path.

1 comment:

Matt Large said...

You can use this as long as you set the SystemId. For example;

StreamSource ssource = new
StreamSource(new FileReader(file));

ssource.setSystemId(file);