Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > XSLT Transformation into String

Reply
Thread Tools

XSLT Transformation into String

 
 
Mathieu
Guest
Posts: n/a
 
      06-01-2006
Hello,

I 'd like to transform xml into another xml by using xslt.

My problem is that input xml and xslt are not in files but in strings.
Moreover output xml must be in string (because I use a database)

My code which doesn't work :

private String convertXML(String xml, String xslt) throws
TransformerException {

SAXResult xmlresult = new SAXResult();
Source xmlsource = new StreamSource(new
StringBufferInputStream(xml));
TransformerFactory xsltfactory = TransformerFactory.newInstance();
Transformer xsltengine = xsltfactory.newTransformer(new
StreamSource(new StringReader(xslt)));
xsltengine.transform(xmlsource,xmlresult);

return xmlresult.toString();
}




The result is bad

Have you got an idea ?

Thanks
 
Reply With Quote
 
 
 
 
Thomas Hawtin
Guest
Posts: n/a
 
      06-01-2006
Mathieu wrote:
>
> I 'd like to transform xml into another xml by using xslt.
>
> My problem is that input xml and xslt are not in files but in strings.
> Moreover output xml must be in string (because I use a database)


Create a javax.xml.transform.stream.StreamResult with the Writer
constructor. Use CharArrayWriter as the Writer implementation, then
toString when you have finished.

Or more efficiently, go for a CharArrayReader. For large results, I
think you can use java.sql.Clob.setCharacterStream (which actually
returns a Writer).

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
 
 
 
Mathieu
Guest
Posts: n/a
 
      06-01-2006
Thanks very very much.

My first test works

Thomas Hawtin a écrit :
> Mathieu wrote:
>>
>> I 'd like to transform xml into another xml by using xslt.
>>
>> My problem is that input xml and xslt are not in files but in strings.
>> Moreover output xml must be in string (because I use a database)

>
> Create a javax.xml.transform.stream.StreamResult with the Writer
> constructor. Use CharArrayWriter as the Writer implementation, then
> toString when you have finished.
>
> Or more efficiently, go for a CharArrayReader. For large results, I
> think you can use java.sql.Clob.setCharacterStream (which actually
> returns a Writer).
>
> Tom Hawtin

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JAXP - Fusing XSLT transformation results into a single XML file Blue Gecko Java 1 10-03-2005 09:39 AM
streaming "for xml" to sax xslt-transformation clogwog Java 0 10-20-2004 05:14 AM
xslt transformation into html and javascript Jon Martin Solaas XML 2 06-15-2004 07:54 AM
Xslt Transformation getting < and > =?Utf-8?B?UGF0Qw==?= ASP .Net 2 05-19-2004 12:15 AM
XSLT TRANSFORMATION FROM XML TO plain Text pradeep gummi XML 3 08-13-2003 03:59 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57