cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alejandro Raiczyk <>
Subject RE: double xslt
Date Wed, 30 Aug 2000 14:06:52 GMT
This was sent by Tagunov Anthony, and I'm working on it, but I guess it will


I guess everyone who tried to chain stylesheets in Cocoon 1.7.4 hit this
problem. I did. Robin Green <> said that's a bug in
Cocoon and sent me his
work around that works fine for me, here it is:

package com.itao.util;

import java.util.Dictionary;
import org.apache.cocoon.framework.Director;
import org.apache.cocoon.processor.Processor;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ProcessingInstruction;

public class StylesheetChainProcessor implements Processor {

  public void init (Director director) {

  public Document process (Document doc, Dictionary parameters) {
    NodeList nl = doc.getChildNodes ();
    for (int i = nl.getLength (); i >= 0; i--) {
      Node n = nl.item (i);
      if (n instanceof ProcessingInstruction) {
        ProcessingInstruction pi = (ProcessingInstruction) n;
        if (pi.getTarget ().equals ("xml-stylesheet")) {
          // remove old stylesheet
          doc.removeChild (pi);
    return doc;

  public boolean hasChanged (Object context) {
    return false; // always does the same thing, so no change
===========================(compile this, make a jar of it and put into
$TOMCAT_HOME/lib directory -- that's my way of doing things -AT)=======
put this into
==processor.type.stylesheet-chain = com.itao.util.StylesheetChainProcessor
in your source .xml file put

<?xml-stylesheet type="text/xsl" href="second.xsl"?>
<?cocoon-process type="xslt"?>
<?cocoon-process type="stylesheet-chain"?>
<?xml-stylesheet type="text/xsl" href="first.xsl"?>
<?cocoon-process type="xslt"?>

Notice that stylesheets must be specified in the reverse order to the order 
in which they should be applied (unlike XSP namespaces, which must be 
specified in the same order).
After I tried that right away I still had a problem but it was with my .xsl
files. Here's Robin's answer to my second problem:
>  Anyway your problem is probably, you MUST copy ALL processing
>  over in the first stylesheet, using:
>   <xsl:template match="processing-instruction()">
>     <xsl:copy-of select="."/>
>   </xsl:template>

In fact after that I put a classical

        <xsl:template match="@*|node()" priority="-1">
in all my stylesheets (or an apropriate analog to it) and it started working
fine. Thanx to Robin Green!  :))))

-----Mensaje original-----
De: Pierpaolo Vittorini []
Enviado el: Martes 29 de Agosto de 2000 12:47 PM
Asunto: double xslt

Hello, I'm new of this list, and I'm trouble because I need to apply two
different and subsequential transformations to an xml document. That is:

              +----+             +----+
  xml_source -|xsl1!-> xml_part -|xsl2|-> html_final, or fo_final
              +----+             +----+

The first transformation applies with no trouble, so the xml_part file
is correct. I mean I've also included

<xsl:processing-instruction name="xml-stylesheet">

in the xsl1 stylesheet...

The problem is that the cocoon servlet does not want to process the
document anymore, in order to transform it into the result..... 
I've tought that this could be the (unallowed) piping among servlets....
everything should pass via the web server, isn't it??? I'm in big trouble

I'm running cocoon 1.7.4, apache 1.3.12, jserv 1.1.2 on a redhat6.2. jdk is
the sun jdk1.2.

Thanks in advance for your time,
Best regards

 Dr. Eng. Pierpaolo Vittorini
   PhD Student at the University of L'Aquila - ITALY
   Department of Electrical Engineering

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message