p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: Same XSLT works for StreamSource but fails for DOMSource


Message #1 by Rajan <rajank@n...> on Mon, 23 Jul 2001 14:50:47 +0530
I suggest you raise this on the Xalan list. One thing I notice is that
you're passing a filename to the parse() method. That isn't supposed to
work: it should be a URL. But Xalan may be forgiving and let you get away
with it.

I would also make the point that it is generally a bad idea to supply a
DOMSource unless you have very good reason to - most XSLT processors will
prefer to build the tree themselves, because it makes it much easier (i.e.
faster) to do things like white space stripping and sorting of nodes into
document order.

Mike Kay
Software AG

> -----Original Message-----
> From: Rajan [mailto:rajank@n...]
> Sent: 23 July 2001 11:40
> To: P2P_XSLT
> Subject: [xslt] RE: Same XSLT works for StreamSource but fails for DOM
> Source
>
>
> Here is the code I am trying..........
>
>     StreamSource stSrc = new
> StreamSource("e:/junk/xsl/periodxsl.xsl");
>     DocumentBuilderFactory dbFac 
> DocumentBuilderFactory.newInstance();
>     dbFac.setValidating(true);
>     DocumentBuilder docBuilder = dbFac.newDocumentBuilder();
>     Document docSrc = docBuilder.parse("e:/junk/xsl/periodxsl.xsl");
>     DOMSource  domSrc = new DOMSource(docSrc);
>
>     TransformerFactory tFac = TransformerFactory.newInstance();
>
>     Transformer tform = tFac.newTransformer(stSrc);---->> Try
> switching
> between stSrc and domSrc
>
>     Document doc = docBuilder.parse("E:/junk/xsl/periodxml.xml");
>     StringWriter sr = new StringWriter();
>     StreamResult res = new StreamResult(sr);
>     tform.transform(new DOMSource(doc), res);
>     System.out.println("Out put is  : " +
> ((StringWriter)res.getWriter()).toString());
>
>
>
> Thanks,
> Rajan
>
> -----Original Message-----
> From: Michael Kay [mailto:mhkay@i...]
> Sent: Monday, July 23, 2001 3:19 PM
> To: P2P_XSLT
> Subject: [xslt] RE: Same XSLT works for StreamSource but fails for
> DOMSource
>
>
> No idea on this one. It might be best to raise it on a Xalan
> list. Perhaps
> you're building the DOM in a way that doesn't preserve namespace
> information - you don't give enough details to see what's going on.
>
> Mike Kay
> Software AG
>
> > -----Original Message-----
> > From: Rajan [mailto:rajank@n...]
> > Sent: 23 July 2001 10:21
> > To: P2P_XSLT
> > Subject: [xslt] Same XSLT works for StreamSource but fails
> > for DOMSource
> >
> >
> > Hi Guys,
> >      I am getting a strange problem... When I try to create
> > Transformer
> > using StreamSource() it works. But fails for DOMSource  for
> same xsl.
> >      As the exceptrion says that it requires "version"
> attribute. This
> > attribute is also there. I am using Xalan2.0.
> >
> > Following is the exception : ---
> >
> > file:///E:\mywork\R&D\xsl\javax.xml.transform.dom.DOMSource;
> > Line 0; Column
> > 0; javax.xml.transform.TransformerConfigurationException: stylesheet
> > requires attribute: version  at
> > org.apache.xalan.processor.TransformerFactoryImpl.newTransform
> > er(Transformer
> > FactoryImpl.java:684)  at TestXSLT.main(TestXSLT.java:24)
> >
> >
> > Any pointers....
> >
> >
> > Thanks,
> > Rajan
> >
> >
>
> ---
> When you work at Microsoft, you don't have to wait for the
> latest technologies to be released. You'll create them ? with
> XML, SOAP, and C# -- and help decide what happens next.
> Find out where your career can take you: take a look at our
> software design engineer opportunities at
> http://www.microsoft.com/jobs.
>


  Return to Index