You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by peter peter <ma...@yahoo.com> on 2003/06/17 04:13:11 UTC

avoid Result parameter in transform method

I am using xalan2.2.1

I am using <redirect> extension to create multiple output files. I don't want to specify any outputfile name(Result) in the transform method, as i want <redirect> to create multiple output files.
 
I am getting following problems.
1. if I use this,
 transformer.transform(new DOMSource(doc),new DOMResult() );
 
 I am getting this exception:
 javax.xml.transform.TransformerException: org.xml.sax.SAXException: Can't have more than one root on a DOM!
2.  If i use this,
 transformerImpl.transform(new DOMSource(doc),new StreamResult() );
 
 I got this exception:
 javax.xml.transform.TransformerException: No output specified
 
3.  If i use this,
 transformerImpl.transform(new DOMSource(doc),new StreamResult("dummy.txt") );
 
 then I got the correct results, But I don't want to use this option as it is creating one dummy.txt file which I don't want.
 
I am ready to send my XSL file if anyone is interested.
Any help or pointers in this regard, will be appreciated.

Regards,
Peter


---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.

Re: avoid Result parameter in transform method

Posted by peter peter <ma...@yahoo.com>.
Hi,
    I identified the problem. 
    I didn't declare extension-element-prefixes="redirect" in the <xsl:stylesheet>, and then I was having this code in the stylesheet.
 
 <redirect:open select="$filename"/> 
 <redirect:write select="$filename">  
 
before any other result tag, So XSLT processor was complaining that it  can't have more than one root node. As soon as i add extension-element-prefixes="redirect", it works fine for me.
 
Thanks,
 


Simon Kitching <si...@ecnetwork.co.nz> wrote:
Hi Peter,

I suspect your output XML is not actually valid.

This is not a valid xml document


because there is more than one element at the "top level".

Neither is this (text nodes must be nested within an element).

some text

However when using a StreamResult, this requirement isn't enforced
as the output doesn't have to be XML.

When using a DOMResult, the result *must* be well-formed XML (which the
above example is not).

However all this DOMResult stuff is not really addressing your problem;
I believe you want to really specify "no destination" for your
transform, because the output isn't actually relevant as you are using
the extension to specify that from within the stylesheet. 

I'm not familiar with the extension, but one possible
solution is to simply use the StreamResult constructor that takes a
ByteArrayOutputStram as the target, rather than a file. Or (more
efficiently), you could write your own trivial Result class which just
discards everything passed to it.


Regards,

Simon

PS: this "Can't have more than one root on a DOM" appears to be a
replacement for the old "DOM_HIERARCHY" error message. A vast
improvement :-)


On Tue, 2003-06-17 at 14:13, peter peter wrote:
> I am using xalan2.2.1
> I am using extension to create multiple output files. I
> don't want to specify any outputfile name(Result) in the transform
> method, as i want to create multiple output files.
> 
> I am getting following problems.
> 1. if I use this,
> transformer.transform(new DOMSource(doc),new DOMResult() );
> 
> I am getting this exception:
> javax.xml.transform.TransformerException: org.xml.sax.SAXException:
> Can't have more than one root on a DOM!
> 2. If i use this,
> transformerImpl.transform(new DOMSource(doc),new StreamResult() );
> 
> I got this exception:
> javax.xml.transform.TransformerException: No output specified
> 
> 3. If i use this,
> transformerImpl.transform(new DOMSource(doc),new
> StreamResult("dummy.txt") );
> 
> then I got the correct results, But I don't want to use this option
> as it is creating one dummy.txt file which I don't want.
> 
> I am ready to send my XSL file if anyone is interested.
> Any help or pointers in this regard, will be appreciated.
> Regards,
> Peter
> 
> 
> ______________________________________________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.



---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.

Re: avoid Result parameter in transform method

Posted by peter peter <ma...@yahoo.com>.
Hi Simon,
    Thanks for the reply,
    I checked once again my XML file is well-formed.
 
Regds,
Peter
    

Simon Kitching <si...@ecnetwork.co.nz> wrote:
Hi Peter,

I suspect your output XML is not actually valid.

This is not a valid xml document


because there is more than one element at the "top level".

Neither is this (text nodes must be nested within an element).

some text

However when using a StreamResult, this requirement isn't enforced
as the output doesn't have to be XML.

When using a DOMResult, the result *must* be well-formed XML (which the
above example is not).

However all this DOMResult stuff is not really addressing your problem;
I believe you want to really specify "no destination" for your
transform, because the output isn't actually relevant as you are using
the extension to specify that from within the stylesheet. 

I'm not familiar with the extension, but one possible
solution is to simply use the StreamResult constructor that takes a
ByteArrayOutputStram as the target, rather than a file. Or (more
efficiently), you could write your own trivial Result class which just
discards everything passed to it.


Regards,

Simon

PS: this "Can't have more than one root on a DOM" appears to be a
replacement for the old "DOM_HIERARCHY" error message. A vast
improvement :-)


On Tue, 2003-06-17 at 14:13, peter peter wrote:
> I am using xalan2.2.1
> I am using extension to create multiple output files. I
> don't want to specify any outputfile name(Result) in the transform
> method, as i want to create multiple output files.
> 
> I am getting following problems.
> 1. if I use this,
> transformer.transform(new DOMSource(doc),new DOMResult() );
> 
> I am getting this exception:
> javax.xml.transform.TransformerException: org.xml.sax.SAXException:
> Can't have more than one root on a DOM!
> 2. If i use this,
> transformerImpl.transform(new DOMSource(doc),new StreamResult() );
> 
> I got this exception:
> javax.xml.transform.TransformerException: No output specified
> 
> 3. If i use this,
> transformerImpl.transform(new DOMSource(doc),new
> StreamResult("dummy.txt") );
> 
> then I got the correct results, But I don't want to use this option
> as it is creating one dummy.txt file which I don't want.
> 
> I am ready to send my XSL file if anyone is interested.
> Any help or pointers in this regard, will be appreciated.
> Regards,
> Peter
> 
> 
> ______________________________________________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.


---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.

Re: avoid Result parameter in transform method

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
Hi Peter,

I suspect your output XML is not actually valid.

This is not a valid xml document
  <foo/>
  <foo/>
because there is more than one element at the "top level".

Neither is this (text nodes must be nested within an element).
  <foo/>
  some text

However when using a StreamResult, this requirement isn't enforced
as the output doesn't have to be XML.

When using a DOMResult, the result *must* be well-formed XML (which the
above example is not).

However all this DOMResult stuff is not really addressing your problem;
I believe you want to really specify "no destination" for your
transform, because the output isn't actually relevant as you are using
the <redirect> extension to specify that from within the stylesheet. 

I'm not familiar with the <redirect> extension, but one possible
solution is to simply use the StreamResult constructor that takes a
ByteArrayOutputStram as the target, rather than a file. Or (more
efficiently), you could write your own trivial Result class which just
discards everything passed to it.


Regards,

Simon

PS: this "Can't have more than one root on a DOM" appears to be a
replacement for the old "DOM_HIERARCHY" error message. A vast
improvement :-)


On Tue, 2003-06-17 at 14:13, peter peter wrote:
> I am using xalan2.2.1
> I am using <redirect> extension to create multiple output files. I
> don't want to specify any outputfile name(Result) in the transform
> method, as i want <redirect> to create multiple output files.
>  
> I am getting following problems.
> 1. if I use this,
>  transformer.transform(new DOMSource(doc),new DOMResult() );
>  
>  I am getting this exception:
>  javax.xml.transform.TransformerException: org.xml.sax.SAXException:
> Can't have more than one root on a DOM!
> 2.  If i use this,
>  transformerImpl.transform(new DOMSource(doc),new StreamResult() );
>  
>  I got this exception:
>  javax.xml.transform.TransformerException: No output specified
>  
> 3.  If i use this,
>  transformerImpl.transform(new DOMSource(doc),new
> StreamResult("dummy.txt") );
>  
>  then I got the correct results, But I don't want to use this option
> as it is creating one dummy.txt file which I don't want.
>  
> I am ready to send my XSL file if anyone is interested.
> Any help or pointers in this regard, will be appreciated.
> Regards,
> Peter
> 
> 
> ______________________________________________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.