----- "Michael Ludwig" <mil...@gmx.de> wrote: > From: "Michael Ludwig" <mil...@gmx.de> > To: xalan-j-users@xml.apache.org > Sent: Thursday, November 12, 2009 7:08:24 PM GMT -07:00 US/Canada Mountain > Subject: Re: Stream Closed on xsl transformation > > Trenton D. Adams schrieb am 12.11.2009 um 16:19:35 (-0700): > > I didn't send an attachment, I sent a link. Do links get removed > too? > > I must have been very tired when looking for the attachment. > > > As for it being 10k, the important part is that it does not work > with > > a processing instruction of "<?xml-stylesheet...?>", but does work > > without one (i.e. specifying one in the java code). It's not the > > XML/XSLT that is important to look at, but the Java code, which is > > very small, and easy to follow, especially considering it's a > simple > > JUnit test. > > Maybe, but it is way more complex than it should have to be. > > Anyway, I get two failures because of: > > junit.framework.AssertionFailedError > caused by > javax.xml.transform.TransformerException > caused by > java.net.UnknownHostException > > And it is little wonder as your stylesheet PI misses a valid URI: > > <?xml-stylesheet type="text/xsl" > href="file://${basedir}/target/test-classes/transcript.xsl"?> > > Corrected this to: > > http://localhost/g/xml-util/target/test-classes/transcript.xsl
Yeah, that's because it's setup to use maven filtering. You have to actually run it through maven to work. It replaces "basedir" with an appropriate path. > > Now: > > junit.framework.AssertionFailedError > caused by > java.io.IOException: Stream closed > > Okay, the error is in reading the PI from the StreamSource by calling > getAssociatedStylesheet(), and then trying to read again from the > same > StreamSource by calling transform(). Streams are to be used once > only. Oh yes, in my rush to get a project done here, I hadn't though of the fact that you can't use the source twice; which is duh, it uses a stream, hehe. Silly me. > > Fixing this in your program is cumbersome, because you have one big > method with parameters of type Object which you then cast to whatever > you need based on what instanceof tells you. > > public static String xslTransformation( > final Object xml, > final Object xsl, > final Map parameters ) > > What's wrong with using polymorphism instead? It's vastly superior. Well, v0.1.X is just a hack to get things done until I have time to fix it all up properly. That is initial development, it isn't always pretty. > > Also, please consider providing simple test cases. You'd have > discovered > this error yourself if you had taken the time to build a simple test > case without so many complicating ingredients. It bears repeating > here > that simplifying is a basic problem solving technique. I don't think it had much to do with the complexity of the code, as it isn't very complex. It had a lot more to do with rushing through. Thanks for the suggestions though. __ This communication is intended for the use of the recipient to whom it is addressed, and may contain confidential, personal, and or privileged information. Please contact us immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communications received in error, or subsequent reply, should be deleted or destroyed. ---