Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT TRANSFORMATION FROM XML TO plain Text

Reply
Thread Tools

XSLT TRANSFORMATION FROM XML TO plain Text

 
 
pradeep gummi
Guest
Posts: n/a
 
      08-12-2003
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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput 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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput 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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      08-12-2003


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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xslutput 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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xslutput 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/

 
Reply With Quote
 
 
 
 
pradeep gummi
Guest
Posts: n/a
 
      08-12-2003
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 <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
> > version="1.0">
> > <xslutput 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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
> > version="1.0">
> > <xslutput 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

 
Reply With Quote
 
pradeep gummi
Guest
Posts: n/a
 
      08-13-2003
Hi Andy,
If you look in the XSL file that I have written you would see
<xslutput 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" <(E-Mail Removed)> wrote in message news:<aq7_a.4275$(E-Mail Removed)>...
> you need to use
>
> <xslutput method="text"/>
>
> this will make sure only text nodes within the output XML get rendered
>
> "pradeep gummi" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
> > version="1.0">
> > <xslutput 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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
> > version="1.0">
> > <xslutput 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

 
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
XML to another XML format transformation using XSLT Binaryx XML 3 04-14-2012 10:20 PM
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
XML file-- XSLT transformation problem with attributes of root element Wolfgang XML 2 04-09-2004 01:20 AM
XSLT transformation that just displays original XML? Matt Bradbury XML 3 08-21-2003 12:53 PM



Advertisments