cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tagunov Anthony" <atagu...@nnt.ru>
Subject Re: [Cocoon Users] XSL chaining.
Date Wed, 30 Aug 2000 06:30:01 GMT
Alejandro Raiczyk wrote:
>Hi people, I was wondering how can I chain XSL Stylesheets ? 
>..

I guess everyone who tried to chain stylesheets in Cocoon 1.7.4 hit this problem. I did. Robin
Green <greenrd@hotmail.com> 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);
          break;
        }
      }
    }
    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 cocoon.properties
==================================================================
==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 instructions 
>  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">
               <xsl:copy><xsl:apply-templates
		select="@*|node()"/></xsl:copy>
	</xsl:template>
in all my stylesheets (or an apropriate analog to it) and it started working fine. Thanx to
Robin Green!  :))))



Mime
View raw message