XSLT TRANSFORMATION FROM XML TO plain Text

P

pradeep gummi

I have an XML FILE that is to be converted to Plain Text using an XSL
file. Since I just want plain text, I do not want to set any root
element during transformation.And if I do not any root element during
transformation, it return s "java.lang.IllegalStateException: Root
element not set" exception. If I add any element for the enclosed
root, it works.
Note: I am using XMLOutputter object of JDOM API, packages
javax.xml.transform and javax.xml.transform.stream.*


Example XML file:
<root><nextpart>test</nextpart></root>


*******************XSL FILE that returns
exception*****************************
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="text" indent="yes"/>
<xsl:template match="root">
<xsl:text>Hello This is the content.</xsl:text>
<xsl:apply-templates select="nextpart"/>
</xsl:template>
...........
</xsl:stylesheet>
************************xsl file****************************


***********************XSL FILE modified*****************************
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="text" indent="yes"/>
<xsl:template match="root">
<document>
<xsl:text>Hello This is the content.</xsl:text>
<xsl:apply-templates select="nextpart"/>
</xsl:template></document>
........
</xsl:stylesheet>
************************xsl file****************************
This change would generate an output:
<document>Hello This is the content.</document>
But I would just want the text without <document> tag.



Any suggestions
thanks
pradeep
 
M

Martin Honnen

pradeep said:
I have an XML FILE that is to be converted to Plain Text using an XSL
file. Since I just want plain text, I do not want to set any root
element during transformation.And if I do not any root element during
transformation, it return s "java.lang.IllegalStateException: Root
element not set" exception. If I add any element for the enclosed
root, it works.
Note: I am using XMLOutputter object of JDOM API, packages
javax.xml.transform and javax.xml.transform.stream.*

I don't know JDOM but if you want to output plain text then XMLOutputter
sounds like the wrong tool to use
 
P

pradeep gummi

Hi Martin,
I need to use JDOM API for that. The outputter classes that it provides are
DOMOutputter, SAXOutputter, XMLOutputter. Any suggestions that I can use of these.
thanks
pradeep
 
P

pradeep gummi

Hi Andy,
If you look in the XSL file that I have written you would see
<xsl:eek:utput method="text" indent="yes"/> enclosed in that. I dont
think that is the problem. My problem is I am using XMLOutputter of
JDOM API which I believe does not output plain text document with out
any root. I would lik to know what kind of object from JDOM api should
I be using that helps to output plain text from XML transformation
without having a root element.
any suggestions...
thanking you
pradeep
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top