I now have a working system, and in case anyone else has the same problem, this is what I had to do:

1. Use an absolutely minimal xsl:output element in the stylesheet:

        <xsl:output encoding="UTF-8" />

2. Create my own serializer based on the standard text serializer, but with a new name and an explicit encoding parameter:

<map:serializer logger="sitemap.serializer.text" mime-type="text/plain"
name="utf8text"
src="org.apache.cocoon.serialization.TextSerializer">


                <encoding>UTF-8</encoding>

        </map:serializer>

3. Use that serializer in my map:match:

         <map:serialize type="utf8text"/>

No other combination (and I tried virtually everything!) would work properly; some caused the null pointer exception in Xalan, some resulted in empty XML documents, and some tripped up when encountering a character with a codepoint above 255.

This was Cocoon 2.1.6 running on Tomcat 5.5, with Java 1.5.

Hope this helps someone!

Martin

Martin Holmes wrote:
Hi there,

When I switch to the XML serializer, I get an empty XML document:

<?xml version="1.0" encoding="ISO-8859-1"?>

with no root element, and the wrong encoding.

This is strange; something must be throwing the Xalan parser for a loop, but there's nothing weird at all in the XSL as far as I can see; it's adapted from another file which works fine on a different installation of Cocoon (2.1.5). I've copied the XSLT below -- can anyone see anything wrong here?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

<!-- output method should be text -->
<xsl:output method="text" encoding="utf-8" media-type="text/plain"/>


<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="l hi" />

<xsl:template match="/">
        <xsl:apply-templates />
</xsl:template>

<!-- Suppress the header -->
<xsl:template match="teiHeader">
    <!-- do nothing! -->
</xsl:template>

<xsl:template match="figure">
  <xsl:text>&#x000d;&#x000a;</xsl:text>
  [<xsl:value-of select="figDesc" />]
  <xsl:text>&#x000d;&#x000a;</xsl:text>
</xsl:template>

<xsl:template match="div | div0 | div1 | div2 | ab | head | p | lg | l | titlePart | docAuthor/name | docAuthor/address/addrLine">
<xsl:text>&#x000d;&#x000a;</xsl:text>
<xsl:apply-templates />
<xsl:text>&#x000d;&#x000a;</xsl:text>
</xsl:template>


<xsl:template match="lb">
    <xsl:text>&#x000d;&#x000a;</xsl:text>
</xsl:template>

<xsl:template match="list">
  <xsl:for-each select="item">
    <xsl:text>&#x000d;&#x000a;</xsl:text>
    <xsl:choose>
      <xsl:when test="../@type='unordered'">
        <xsl:text>&#x2022;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="position()" />.
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates />
    <xsl:text>&#x000d;&#x000a;</xsl:text>
  </xsl:for-each>
</xsl:template>

 <xsl:template match="note">
   <xsl:choose>
     <xsl:when test="@n">
       [Note <xsl:value-of select="@n"/>: <xsl:apply-templates />]
     </xsl:when>
     <xsl:otherwise>
       <xsl:apply-templates />
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>

<xsl:template match="cit"><xsl:if test="q">"<xsl:apply-templates select="q" />"</xsl:if><xsl:if test="bibl"> (<xsl:apply-templates select="bibl" />)</xsl:if>
</xsl:template>


  <xsl:template match="biblStruct">
    <xsl:text>&#x000d;&#x000a;</xsl:text>
      <xsl:apply-templates />
  </xsl:template>

<xsl:template match="biblStruct//title | biblStruct//publisher | biblStruct//pubPlace | biblStruct//date | biblStruct//biblScope">
<xsl:text>&#x000d;&#x000a;</xsl:text>
<xsl:apply-templates />
</xsl:template>


  <xsl:template match="biblStruct//name">
    <xsl:text>&#x000d;&#x000a;</xsl:text>
    <xsl:value-of select="@reg" />
  </xsl:template>

<xsl:template match="text()">
    <xsl:value-of select="." />
</xsl:template>

Cheers,
Martin

</xsl:stylesheet>

Upayavira wrote:

Martin Holmes wrote:

I'm having problems generating plain text output (utf-8) on Cocoon 2.1.6. I get a NullPointerException. The scenario is:

      <map:match pattern="proof/*.txt">
        <map:generate src="abstracts_for_proofing/{1}.xml"/>
        <map:transform type="xinclude"/>
        <map:transform type="xslt" src="xsl/text_out.xsl"/>
        <map:serialize type="text" />
      </map:match>

The XML files are UTF-8 and the XSL file starts out like this:


<xsl:output method="text" encoding="utf-8" media-type="text/plain"/>

<xsl:template match="/">
     <xsl:processing-instruction
name="cocoon-format">type="text/plain"</xsl:processing-instruction>
     <plain-text>
        <xsl:apply-templates />
    </plain-text>
</xsl:template>

The XSL works fine running locally in oXygen with Saxon 6.5.3. I've tried removing the processing instruction, but it makes no difference. I've also tried adding a UTF-8 text serializer to the sitemap like this:

<map:serializer logger="sitemap.serializer.text" mime-type="text/plain"
name="text" src="org.apache.cocoon.serialization.TextSerializer">
<encoding>UTF-8</encoding>
</map:serializer>


but no joy.

I've included the top few lines of the stack trace below. Can anyone suggest what the problem might be?



Thanks for the other stack trace. Unfortunately, those ones are usually very difficult to debug, as the error shows up in Xalan as a null pointer exception, which was actually triggered by something much further back in the pipeline.


Now, have you tried replacing <map:serialize type="text"/> with <map:serialize type="xml"/>

What do you see? Does it produce your text content, but wrapped in XML?

Also, the processing instruction, to my knowledge, won't make any difference. It looks like a Cocoon 1.x instruction, that Cocoon 2 doesn't know about. Configuration like that happens in the sitemap, not in processing instructions.

Regards, Upayavira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to