You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Alejandro Raiczyk <al...@technisys.com.ar> on 2000/08/29 22:10:41 UTC
XSL chaining.
Hi people, I was wondering how can I chain XSL Stylesheets ?
I'm doing it this way:
<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="filtroIdioma.xsl" type="text/xsl"?>
<?xml-stylesheet href="estilo.xsl" type="text/xsl"?>
<xsp:page
language="java"
xmlns:xsp="http://www.apache.org/1999/XSP/Core"
>
.
.
I want to process with filtroIdioma.xsl first, and then with estilo.xsl but
this is not working.
The both are working when I call them alone.
What am I doing wrong ??
Thanks!
Re: [Cocoon Users] XSL chaining.
Posted by Tagunov Anthony <at...@nnt.ru>.
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 <gr...@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! :))))