XSLT FAQs
http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Main

FAQs
Index

Getting Started
Install
Configure
CVS

Using
Configure C2
Databases
XSP
XSLT
Debugging

Sitemap
Sitemap
Generators
Transformers
Serializers
Matchers
Selectors
Actions
Aggregators

Questions
Answers
How do I tell Cocoon to stop adding carriage-returns during XSL transformation?

The short answer is that this is not a Cocoon issue. You need to read up on XSLT usage. Please see other resources for XSLT, specifically, the XSL FAQ and discussion lists.

The long answer is that you need to use the XSLT function normalize-space() whenever you want to rely on the content of an xml element.

For example, if your application is producing some Javascript code in your HTML output, then you might mistakenly try to use the following construct in your XSL stylesheet:

alert('<xsl:value-of select="message"/>');

which will produce:

alert('
messageValue
');

The line-endings in the content of your "message" element will cause javascript errors. Instead, do this:

alert('<xsl:value-of select="normalize-space(message)"/>');

Note that there are many more issues about whitespace handling. Please refer to the relevant XSLT resources rather than clutter up the Cocoon discussion lists.

Is (your description here) kind of functionality appropriate for a stylesheet?

When this kind of question arises, ask yourself:

  • Am I using my stylesheet to address style concerns, or am I programming with it?
  • Could I solve this problem once and for all during Generation?
  • Isn't my problem better solved with a Transformer, since it requires coding?

There is not one, nor only one, answer. In Cocoon, you can accomplish the same thing in a number of different ways. Nonetheless, if your transformation depends on something specific happening during generation, it will be more difficult to reuse your code.

Here's a hint. Do all that you possibly can in a Generator. Add only what is absolutely necessary with Transformers. Use stylesheets to change format or style, not to code. This approach will make your system more manageable and reusable because it removes dependencies between components.

Can I use the same XSLT processor and still specify different processing options for different pipelines?

For example, I found that PDF processing is faster with Xalan when I turn incremental processing off.

Yes. For Cocoon version 2.0.3, check out the following Cocoon snippet.

Can I use different XSLT processors when processing different pipelines?

Yes. For Cocoon version 2.0.3, adapt the approach discussed in the following Cocoon snippet.

How can I remove namespaces from my xml files?

Sometimes adding xsl:exclude-result-prefixes attributes to the <xsl:stylesheet> or literal result element is not effective in removing all namespace declarations. For example, namespace nodes copied from the source document within <xsl:copy> or <xsl:copy-of> instructions (commonly found in catch-all stylesheet templates) will not be excluded.

There are two approaches to this problem.

One approach is to add a transformation step in your pipeline (or adjust your final stylesheet) with the following:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="*">
      <!-- remove element prefix (if any) -->
      <xsl:element name="{local-name()}">
        <!-- process attributes -->
        <xsl:for-each select="@*">
          <!-- remove attribute prefix (if any) -->
          <xsl:attribute name="{local-name()}">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </xsl:for-each>
        <xsl:apply-templates/>
      </xsl:element>
  </xsl:template>
</xsl:stylesheet>

Another approach is to extend your serializer component, described here.

How can I add my FAQ to this document?

Follow the instructions found in How-To Author an FAQ.

How can I suggest improvements to existing FAQs?

Given the rapid pace of change with Cocoon, many individual FAQs quickly become out-of-date and confusing to new users. If you have the relevant knowledge, please consider updating other FAQs on this page for technical errors. If you see a few typos, please consider fixing them too. Follow the instructions found in How-To Author an FAQ.

Copyright © 1999-2002 The Apache Software Foundation. All Rights Reserved.