You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Abid Ali Teepo <ab...@mogul.com> on 2001/02/06 17:38:02 UTC

Plain text from Cocoon

Hi!

I wan't plain text output from cocoon, but somehow it gives an
error message unless i include som html-tags. How can i get plain 
text without the tags ?

My XML page looks like this :
------------------------------------------------------------------------
-
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="phonebook-plain.xsl" type="text/xsl"?>
<?cocoon-process type="xslt"?>
<Personalia>
	<Navn><Fornavn>Ole<Initialer>O.O</Initialer>
		</Fornavn>
		<Etternavn>Olsen</Etternavn>
	</Navn>
	<Navn><Fornavn>Per<Initialer>P.P</Initialer>
		</Fornavn>
		<Etternavn>Person</Etternavn>
	</Navn>
</Personalia>
------------------------------------------------------------------------
-
And my XSL page looks like this :
------------------------------------------------------------------------
-
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

	<xsl:template match="Personalia">
				<xsl:for-each select="Navn">
	 <xsl:value-of select="Fornavn" /> 
					     		
				</xsl:for-each>
			</xsl:template>
</xsl:stylesheet>
------------------------------------------------------------------------
---
The ERROR message looks like this :
------------------------------------------------------------------------
---



Error found handling the request.
org.apache.xalan.xslt.XSLProcessorException: Warning: can't output text
before document element!  Ignoring...
	at
org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1710)
	at
org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1674)
	at
org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:703)
	at
org.apache.cocoon.transformer.XalanTransformer.transform(XalanTransforme
r.java:107)
	at
org.apache.cocoon.processor.xslt.XSLTProcessor.process(XSLTProcessor.jav
a:116)
	at org.apache.cocoon.Engine.handle(Engine.java:384)
	at org.apache.cocoon.Cocoon.service(Cocoon.java:183)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.
java:208)
	at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServl
etContext.java:1127)
	at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.
java:1529)
	at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
	at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
---------
org.xml.sax.SAXException: Warning: can't output text before document
element!  Ignoring...
	at
org.apache.xalan.xpath.xml.FormatterToDOM.append(FormatterToDOM.java:147
)
	at
org.apache.xalan.xpath.xml.FormatterToDOM.characters(FormatterToDOM.java
:331)
	at
org.apache.xalan.xslt.XSLTEngineImpl$ResultTreeHandler.characters(XSLTEn
gineImpl.java:4021)
	at
org.apache.xalan.xslt.ElemValueOf.execute(ElemValueOf.java:211)
	at
org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateEl
ement.java:661)
	at
org.apache.xalan.xslt.ElemTemplateElement.transformChild(ElemTemplateEle
ment.java:1199)
	at
org.apache.xalan.xslt.ElemTemplateElement.processLocatedNode(ElemTemplat
eElement.java:1061)
	at
org.apache.xalan.xpath.SimpleNodeLocator.findChildren(SimpleNodeLocator.
java:773)
	at
org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java:428
)
	at
org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.
java:321)
	at org.apache.xalan.xpath.XPath.locationPath(XPath.java:964)
	at org.apache.xalan.xpath.XPath.execute(XPath.java:1385)
	at org.apache.xalan.xpath.XPath.execute(XPath.java:1354)
	at org.apache.xalan.xpath.XPath.execute(XPath.java:311)
	at
org.apache.xalan.xslt.ElemTemplateElement.transformSelectedChildren(Elem
TemplateElement.java:896)
	at
org.apache.xalan.xslt.ElemForEach.execute(ElemForEach.java:134)
	at
org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateEl
ement.java:661)
	at
org.apache.xalan.xslt.ElemTemplateElement.transformChild(ElemTemplateEle
ment.java:1199)
	at
org.apache.xalan.xslt.ElemTemplateElement.processLocatedNode(ElemTemplat
eElement.java:1061)
	at
org.apache.xalan.xpath.SimpleNodeLocator.findChildren(SimpleNodeLocator.
java:773)
	at
org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java:428
)
	at
org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.
java:321)
	at org.apache.xalan.xpath.XPath.locationPath(XPath.java:964)
	at org.apache.xalan.xpath.XPath.execute(XPath.java:1385)
	at org.apache.xalan.xpath.XPath.execute(XPath.java:1354)
	at org.apache.xalan.xpath.XPath.execute(XPath.java:311)
	at
org.apache.xalan.xslt.ElemTemplateElement.transformSelectedChildren(Elem
TemplateElement.java:896)
	at
org.apache.xalan.xslt.ElemApplyTemplates.execute(ElemApplyTemplates.java
:176)
	at
org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateEl
ement.java:661)
	at
org.apache.xalan.xslt.ElemTemplate.execute(ElemTemplate.java:145)
	at
org.apache.xalan.xslt.StylesheetRoot.process(StylesheetRoot.java:444)
	at
org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:679)
	at
org.apache.cocoon.transformer.XalanTransformer.transform(XalanTransforme
r.java:107)
	at
org.apache.cocoon.processor.xslt.XSLTProcessor.process(XSLTProcessor.jav
a:116)
	at org.apache.cocoon.Engine.handle(Engine.java:384)
	at org.apache.cocoon.Cocoon.service(Cocoon.java:183)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.
java:208)
	at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServl
etContext.java:1127)
	at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.
java:1529)
	at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
	at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

Re: Plain text from Cocoon

Posted by Alain Ketterlin <al...@dpt-info.u-strasbg.fr>.
Abid Ali Teepo ( 6 Feb) writes:

> I wan't plain text output from cocoon, but somehow it gives an
> error message unless i include som html-tags. How can i get plain 
> text without the tags ?

I had to wrap the text-content in a dummy element. My root template
looks like:

  <xsl:template match="/">
    <bouh>
Bla bla
...
    </bouh>
  </xsl:template>

Add a <?cocoon-format type="text/plain"?> in your xml, and the
TextFormatter will ignore the root element (i.e. it will take the
string value of it, IIRC).

-- Alain.

Re: Plain text from Cocoon

Posted by Corey O'Donovan <od...@feersumendjinns.com>.
Hi,

You have to use a root tag in xsl, but it won't show in the resulting
document if you set the format to text/plain.
Try this stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="Personalia">
 <xsl:processing-instruction
name="cocoon-format">type="text/plain"</xsl:processing-instruction>
 <plain-text>
  <xsl:for-each select="Navn">
   <xsl:value-of select="Fornavn" />
  </xsl:for-each>
 </plain-text>
</xsl:template>
</xsl:stylesheet>

Corey

----- Original Message -----
From: Abid Ali Teepo <ab...@mogul.com>
To: <co...@xml.apache.org>
Sent: Tuesday, February 06, 2001 4:38 PM
Subject: Plain text from Cocoon


>
> Hi!
>
> I wan't plain text output from cocoon, but somehow it gives an
> error message unless i include som html-tags. How can i get plain
> text without the tags ?
>
> My XML page looks like this :
> ------------------------------------------------------------------------
> -
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet href="phonebook-plain.xsl" type="text/xsl"?>
> <?cocoon-process type="xslt"?>
> <Personalia>
> <Navn><Fornavn>Ole<Initialer>O.O</Initialer>
> </Fornavn>
> <Etternavn>Olsen</Etternavn>
> </Navn>
> <Navn><Fornavn>Per<Initialer>P.P</Initialer>
> </Fornavn>
> <Etternavn>Person</Etternavn>
> </Navn>
> </Personalia>
> ------------------------------------------------------------------------
> -
> And my XSL page looks like this :
> ------------------------------------------------------------------------
> -
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
>
> <xsl:template match="Personalia">
> <xsl:for-each select="Navn">
> <xsl:value-of select="Fornavn" />
>
> </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
> ------------------------------------------------------------------------
> ---
> The ERROR message looks like this :
> ------------------------------------------------------------------------
> ---
>
>
>
> Error found handling the request.
> org.apache.xalan.xslt.XSLProcessorException: Warning: can't output text
> before document element!  Ignoring...
> at
> org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1710)
> at
> org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1674)
> at
> org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:703)
> at
> org.apache.cocoon.transformer.XalanTransformer.transform(XalanTransforme
> r.java:107)
> at
> org.apache.cocoon.processor.xslt.XSLTProcessor.process(XSLTProcessor.jav
> a:116)
> at org.apache.cocoon.Engine.handle(Engine.java:384)
> at org.apache.cocoon.Cocoon.service(Cocoon.java:183)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
> weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.
> java:208)
> at
> weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServl
> etContext.java:1127)
> at
> weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.
> java:1529)
> at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
> at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
> ---------
> org.xml.sax.SAXException: Warning: can't output text before document
> element!  Ignoring...
> at
> org.apache.xalan.xpath.xml.FormatterToDOM.append(FormatterToDOM.java:147
> )
> at
> org.apache.xalan.xpath.xml.FormatterToDOM.characters(FormatterToDOM.java
> :331)
> at
> org.apache.xalan.xslt.XSLTEngineImpl$ResultTreeHandler.characters(XSLTEn
> gineImpl.java:4021)
> at
> org.apache.xalan.xslt.ElemValueOf.execute(ElemValueOf.java:211)
> at
> org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateEl
> ement.java:661)
> at
> org.apache.xalan.xslt.ElemTemplateElement.transformChild(ElemTemplateEle
> ment.java:1199)
> at
> org.apache.xalan.xslt.ElemTemplateElement.processLocatedNode(ElemTemplat
> eElement.java:1061)
> at
> org.apache.xalan.xpath.SimpleNodeLocator.findChildren(SimpleNodeLocator.
> java:773)
> at
> org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java:428
> )
> at
> org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.
> java:321)
> at org.apache.xalan.xpath.XPath.locationPath(XPath.java:964)
> at org.apache.xalan.xpath.XPath.execute(XPath.java:1385)
> at org.apache.xalan.xpath.XPath.execute(XPath.java:1354)
> at org.apache.xalan.xpath.XPath.execute(XPath.java:311)
> at
> org.apache.xalan.xslt.ElemTemplateElement.transformSelectedChildren(Elem
> TemplateElement.java:896)
> at
> org.apache.xalan.xslt.ElemForEach.execute(ElemForEach.java:134)
> at
> org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateEl
> ement.java:661)
> at
> org.apache.xalan.xslt.ElemTemplateElement.transformChild(ElemTemplateEle
> ment.java:1199)
> at
> org.apache.xalan.xslt.ElemTemplateElement.processLocatedNode(ElemTemplat
> eElement.java:1061)
> at
> org.apache.xalan.xpath.SimpleNodeLocator.findChildren(SimpleNodeLocator.
> java:773)
> at
> org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java:428
> )
> at
> org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.
> java:321)
> at org.apache.xalan.xpath.XPath.locationPath(XPath.java:964)
> at org.apache.xalan.xpath.XPath.execute(XPath.java:1385)
> at org.apache.xalan.xpath.XPath.execute(XPath.java:1354)
> at org.apache.xalan.xpath.XPath.execute(XPath.java:311)
> at
> org.apache.xalan.xslt.ElemTemplateElement.transformSelectedChildren(Elem
> TemplateElement.java:896)
> at
> org.apache.xalan.xslt.ElemApplyTemplates.execute(ElemApplyTemplates.java
> :176)
> at
> org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateEl
> ement.java:661)
> at
> org.apache.xalan.xslt.ElemTemplate.execute(ElemTemplate.java:145)
> at
> org.apache.xalan.xslt.StylesheetRoot.process(StylesheetRoot.java:444)
> at
> org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:679)
> at
> org.apache.cocoon.transformer.XalanTransformer.transform(XalanTransforme
> r.java:107)
> at
> org.apache.cocoon.processor.xslt.XSLTProcessor.process(XSLTProcessor.jav
> a:116)
> at org.apache.cocoon.Engine.handle(Engine.java:384)
> at org.apache.cocoon.Cocoon.service(Cocoon.java:183)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
> weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.
> java:208)
> at
> weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServl
> etContext.java:1127)
> at
> weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.
> java:1529)
> at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
> at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>


Re: Plain text from Cocoon

Posted by "Peter C. Verhage" <pe...@zeelandnet.nl>.
----- Original Message -----
From: "Berin Loritsch" <bl...@apache.org>
To: <co...@xml.apache.org>
Sent: Tuesday, February 06, 2001 6:13 PM
Subject: Re: Plain text from Cocoon

: > You probably can't. Because of the simple reason that XSL(T) is ment for
: > transforming one XML file to another. So you always have to make a XML
tree
: > with XSLT, whatever the program that interprets the output does with it
is
: > up to the program (for example transform it to a PDF or HTML document),
but
: > you cannot use XSLT to create a plain text file without at least some
root
: > tag.
:
: That's not necessarily true.  Otherwise XSP and VRML won't work.  The
: way it works in Cocoon, is you must have root tags.  Everything can be
: translated to text inside the base tags.  The TextSerializer or
: similar mechanism in Cocoon 1 will strip out the root tags.

I understand what you mean, but when you look at XSLT it is true what I am
saying, and like I said, it depends also on the program that interprets the
output. In this case the program is Cocoon, and Cocoon knows to strip the
root element if the type is text/plain probably.

Ofcourse this last thing I did not know :P.

Regards,

Peter


Re: Plain text from Cocoon

Posted by Berin Loritsch <bl...@apache.org>.
"Peter C. Verhage" wrote:
> 
> << Hi!
> 
> I wan't plain text output from cocoon, but somehow it gives an
> error message unless i include som html-tags. How can i get plain
> text without the tags ? >>
> 
> You probably can't. Because of the simple reason that XSL(T) is ment for
> transforming one XML file to another. So you always have to make a XML tree
> with XSLT, whatever the program that interprets the output does with it is
> up to the program (for example transform it to a PDF or HTML document), but
> you cannot use XSLT to create a plain text file without at least some root
> tag.

That's not necessarily true.  Otherwise XSP and VRML won't work.  The
way it works in Cocoon, is you must have root tags.  Everything can be
translated to text inside the base tags.  The TextSerializer or
similar mechanism in Cocoon 1 will strip out the root tags.

Example:

<root>
This is plain text.

We can have some more text.

And even some more.
</root>

When put through the TextSerializer, will strip the root tags and you get:

"This is plain text.

We can have some more text.

And even some more."

(quotes included to show that it is one string).

Re: Plain text from Cocoon

Posted by "Peter C. Verhage" <pe...@zeelandnet.nl>.
<< Hi!

I wan't plain text output from cocoon, but somehow it gives an
error message unless i include som html-tags. How can i get plain
text without the tags ? >>

You probably can't. Because of the simple reason that XSL(T) is ment for
transforming one XML file to another. So you always have to make a XML tree
with XSLT, whatever the program that interprets the output does with it is
up to the program (for example transform it to a PDF or HTML document), but
you cannot use XSLT to create a plain text file without at least some root
tag.

Peter