You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by loic tregan <lt...@hotmail.com> on 2000/09/25 21:07:33 UTC
two problems
Hi all,
I have dowloaded what seems to be a safe version of xalan-j (1_2_D02), but
I experience two basic problems in the following code:
XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
FileInputStream xml = new FileInputStream("c:\\temp\\foo.xml");
FileInputStream xsl = new FileInputStream("c:\\temp\\foo.xsl");
XSLTInputSource xmlID = new XSLTInputSource(xml);
XSLTInputSource stylesheetID = new XSLTInputSource(xsl);
Document out = new org.apache.xerces.dom.DocumentImpl();
XSLTResultTarget resultTarget = new XSLTResultTarget(out);
processor.process(xmlID, stylesheetID, resultTarget);
1) new XSLTInputSource("c:\\temp\\foo.xml"); does not work ("file not
found"), I have to use a intermediary FileInputStream as shown above
2) processor.process(...) issues this error message : "Cannot use a
DTMLiaison for an output DOM node... pass a
org.apache.xalan.xpath.xdom.XercesLiaison instead!".
Is it me or what ?
thanks for your attention.
PS : I've not subscribe yet, please forward me your answers !
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at
http://profiles.msn.com.
processing does not work with Node
Posted by Loïc Trégan <lt...@hotmail.com>.
Hi all,
I can not explain the output produced by the above code; is it a bug ? My
current workaround is to stream my Node then use the file as input; anything
better ?
Once fixed, it would be easier if both (1) and (2) can be used : in some
cases I want to process only a branch of my Document.
Thanks for your help.
PS : please send me personnaly a copy of your potential answer(s).
static public void TestXalanBUGGYDOM2() throws Exception {
// create simple XSL
String SIMPLE_XSL =
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"
version=\"1.0\">"
+"<xsl:template match=\"/\">"
+" This is XSL <xsl:apply-templates select=\"*\" /> "
+"</xsl:template>"
+"</xsl:stylesheet>";
// create simple DOM
XMLParserLiaison parserLiaison = new
org.apache.xalan.xpath.xdom.XercesLiaison();
Document doc = parserLiaison.createDocument();
Node root = doc.createElement( "root" );
Node text = doc.createTextNode( "This is XML");
root.appendChild( text );
// set sources
// XSLTInputSource xmlID = new XSLTInputSource( root ); // (1)error:
output="This is XML"
// XSLTInputSource xmlID = new XSLTInputSource( doc ); // (2)error:
output="This is XSL"
XSLTInputSource xmlID = new XSLTInputSource( "file:c:/temp/root.xml" );
// (3)correct : output="This is XSL This XML"
XSLTInputSource stylesheetID = new XSLTInputSource( new
StringReader(SIMPLE_XSL) );
XSLTResultTarget resultTarget = new XSLTResultTarget(System.out);
// display
XSLTProcessor processor =
XSLTProcessorFactory.getProcessor(parserLiaison);
processor.process(xmlID, stylesheetID, resultTarget);
}
unfair error message with XSLTInputSource(String)
Posted by Loïc Trégan <lt...@hotmail.com>.
Hi all,
// ok
XSLTInputSource xmlID = new XSLTInputSource("foo.xml");
// ok
XSLTInputSource xmlID = new XSLTInputSource("file:c:/temp/foo.xml");
// error message : "Could not parse c:/temp/foo.xml document!"
XSLTInputSource xmlID = new XSLTInputSource("c:/temp/foo.xml");
Given the error message and the basic examples (where the xml file is
stored in current directory), it is not easy to find the correct syntax;
maybe describe it in the javadoc for XSLTInputSource( String ), and in the
"code pattern".
thanks for your attention
loic
too many lines in HTML output
Posted by Loïc Trégan <lt...@hotmail.com>.
Hi again,
The here-under code displays :
<html>
</html>
instead of :
<html>
</html>
in HTML mode, the problem diseapper. Have I done something wrong or is it a
bug from Xalan ? Is there a better solution than replacing CRLF by CR in my
code ?
thanks for your help
loic
static public void main( String argv[] ) {
try {
// create doc
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance ();
DocumentBuilder db = dbf.newDocumentBuilder ();
Document doc = db.newDocument ();
Node html = doc.createElement("html");
Node text =
oc.createTextNode( String.valueOf((char)13)+String.valueOf((char)10) );
html.appendChild( text );
//
XSLTInputSource xmlID = new XSLTInputSource(html);
XSLTInputSource xslID = new XSLTInputSource( new
StringReader(XML.IDENTITY_XSL));
XSLTResultTarget resultTarget = new XSLTResultTarget(System.out);
XSLTProcessor processor = XSLTProcessorFactory.getProcessor(
new org.apache.xalan.xpath.xdom.XercesLiaison()
);
StylesheetRoot stylesheet = processor.processStylesheet(xslID);
stylesheet.setOutputMethod("XML");
stylesheet.process(processor, xmlID, resultTarget);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
Re: two problems
Posted by Gary L Peskin <ga...@firstech.com>.
loic tregan wrote:
>
> Hi all,
>
> I have dowloaded what seems to be a safe version of xalan-j (1_2_D02), but
> I experience two basic problems in the following code:
>
> XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
> FileInputStream xml = new FileInputStream("c:\\temp\\foo.xml");
> FileInputStream xsl = new FileInputStream("c:\\temp\\foo.xsl");
> XSLTInputSource xmlID = new XSLTInputSource(xml);
> XSLTInputSource stylesheetID = new XSLTInputSource(xsl);
> Document out = new org.apache.xerces.dom.DocumentImpl();
> XSLTResultTarget resultTarget = new XSLTResultTarget(out);
> processor.process(xmlID, stylesheetID, resultTarget);
>
> 1) new XSLTInputSource("c:\\temp\\foo.xml"); does not work ("file not
> found"), I have to use a intermediary FileInputStream as shown above
>
> 2) processor.process(...) issues this error message : "Cannot use a
> DTMLiaison for an output DOM node... pass a
> org.apache.xalan.xpath.xdom.XercesLiaison instead!".
>
> Is it me or what ?
Try new XSLTInputSource("file:///c:/temp/foo.xml"). I think this may
fix both problems.
Gary