Hi,

While transforming an XML document by applying an xsl stylesheet, I am
encountering this run time error:

Suppose there is a file called "mt540.xsl" which you need to apply to the
XML document, then the following statement:

Transformer oXSLTransformer =
TransformerFactory.newInstance().newTransformer(new
StreamSource("mt540.xsl")); 

successfully loads the stylesheet into the Transformer.

But if suppose I have previously loaded the XSL stylesheet into a Document
such as:
SAXReader oXSLReader = new SAXReader();
oXSLDoc = oXSLReader.read("mt540.xsl");
//statements
/* Then if I try to load the Transformer with the DocumentSource class by
reading the xsl content, it give the following error*/
Transformer oXSLTransformer =
TransformerFactory.newInstance().newTransformer(new
DocumentSource(org.dom4j.DocumentHelper.parseText(oXSLDoc.asXML())));

java.lang.IllegalArgumentException: System ID must not be null
        at
com.icl.saxon.tree.DocumentImpl.setSystemId(DocumentImpl.java:119)
        at com.icl.saxon.tree.TreeBuilder.startDocument(TreeBuilder.java:89)
        at
com.icl.saxon.output.ProxyEmitter.startDocument(ProxyEmitter.java:61)
        at com.icl.saxon.om.Stripper.startDocument(Stripper.java:145)
        at
com.icl.saxon.ContentEmitter.startDocument(ContentEmitter.java:63)
        at org.dom4j.io.SAXWriter.startDocument(SAXWriter.java:496)
        at org.dom4j.io.SAXWriter.write(SAXWriter.java:123)
        at org.dom4j.io.SAXWriter.parse(SAXWriter.java:389)
        at com.icl.saxon.om.Builder.build(Builder.java:242)
        at
com.icl.saxon.PreparedStyleSheet.prepare(PreparedStyleSheet.java:111)
        at
com.icl.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.jav
a:126)
        at
com.icl.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.j
ava:78)
        at
com.interrait.domutil.DOMDocumentEx.transform(DOMDocumentEx.java:116)
        at com.interrait.domutil.DOMDocumentEx.main(DOMDocumentEx.java:217)

First of all, can the transformer be loded with the xsl content as a string,
or can it only be loded from a file reference? The above statement works if
in the constructor new StreamSource(), I pass a File object, but fails if I
pass a FileInputStream object.

i.e. Transformer oXSLTransformer =
TransformerFactory.newInstance().newTransformer(new StreamSource(new
File("mt540.xsl"))); //works
but
Transformer oXSLTransformer =
TransformerFactory.newInstance().newTransformer(new StreamSource(new
FileInputStream("mt540.xsl"))); //fails

Same occurs with the new DocumentSource() constructor. 

If I do:
DocumentResult oDoc = new
DocumentSource(org.dom4j.DocumentHelper.parseText(oXSLDocEx.asXML()));
System.out.println(oDoc.getDocument().asXML());

then the content of the XSL document shows correctly. Under what
circumstances does this method newTransformer() succeed or fail? I'd
appreciate any comments about what's wrong with the above statements. I
apologize if this is off context, but I suppose many of you have been
working on XML+XSL transformations to have some idea about this.

Thanks
Soumanjoy

_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to