XSLT TRANSFORMATION FROM XML TO plain Text

Discussion in 'XML' started by pradeep gummi, Aug 12, 2003.

  1. 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
    pradeep gummi, Aug 12, 2003
    #1
    1. Advertising

  2. 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: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



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Aug 12, 2003
    #2
    1. Advertising

  3. 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 <> wrote in message news:<>...
    > 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: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
    pradeep gummi, Aug 12, 2003
    #3
  4. 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


    "Andy Fish" <> wrote in message news:<aq7_a.4275$>...
    > you need to use
    >
    > <xsl:eek:utput method="text"/>
    >
    > this will make sure only text nodes within the output XML get rendered
    >
    > "pradeep gummi" <> wrote in message
    > news:...
    > > 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
    pradeep gummi, Aug 13, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. clogwog
    Replies:
    0
    Views:
    422
    clogwog
    Oct 20, 2004
  2. Blue Gecko
    Replies:
    1
    Views:
    443
    Blue Gecko
    Oct 3, 2005
  3. Matt Bradbury
    Replies:
    3
    Views:
    457
    Dimitre Novatchev
    Aug 21, 2003
  4. Wolfgang
    Replies:
    2
    Views:
    825
    Wolfgang
    Apr 9, 2004
  5. Binaryx
    Replies:
    3
    Views:
    5,092
    Peter Flynn
    Apr 14, 2012
Loading...

Share This Page