473,507 Members | 12,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT TRANSFORMATION FROM XML TO plain Text

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:output 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:output 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
Jul 20 '05 #1
3 7894


pradeep gummi wrote:
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


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:output 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:output 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

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
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

Martin Honnen <Ma***********@t-online.de> wrote in message news:<3F**************@t-online.de>...
pradeep gummi wrote:
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


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:output 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:output 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

Jul 20 '05 #3
Hi Andy,
If you look in the XSL file that I have written you would see
<xsl:output 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
"Andy Fish" <aj****@blueyonder.co.uk> wrote in message news:<aq********************@news-text.cableinet.net>...
you need to use

<xsl:output method="text"/>

this will make sure only text nodes within the output XML get rendered

"pradeep gummi" <pr***********@villanova.edu> wrote in message
news:ba**************************@posting.google.c om...
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:output 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:output 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

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2681
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
6
2721
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
1
3086
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
4
5227
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x =...
5
4393
by: shauldar | last post by:
Is there a way (tool, hack...) to create an XSL:FO from an XSLT + XML files? My motivation is that we want to use a tool to design reports, and from that "design" generate both HTML (via XSLT)...
4
2128
by: simon.a.hulbert | last post by:
Hi, I'm trying to view the following xslt transformation using firefox <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" > <xsl:output method = "xml" indent =...
2
3088
by: Jonny B | last post by:
Hi all, I'm working on an a clientside xslt using jscript that passes a parameter to the xsl. I've got it working no problem in IE but cant get it to work in Mozilla. Can anyone help? This is...
2
6288
by: psaffrey | last post by:
I'd like to read a one-line text file using an XSLT transformation. I'm using libxslt, so I have to use XSLT 1.0. This post: http://www.stylusstudio.com/xsllist/200508/post50080.html is...
3
4503
by: joelkeepup | last post by:
Hi, im trying to create a text email message using xslt template , the transforms work great, but the newlines and whitespace in the xslt doc are removed. Is there a setting somewhere I have...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.