cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Edwards, Jayme" <>
Subject document() function failing in Xalan 2.1.0 under Cocoon 1.8.2
Date Mon, 18 Jun 2001 10:15:44 GMT
I've been using Xalan 2.1.0 with Cocoon 1.8.2 by configuring a Xalan2Transformer I wrote to
adapt Xalan2 to Cocoon. You just compile this class under whatever package name you want and
set it as the transformer property in your file. The code for the transformer
follows and then a brief description of the problem I'm having.
import java.util.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import org.w3c.dom.*;
import org.apache.cocoon.parser.*;
import org.apache.cocoon.processor.*;
import org.apache.cocoon.framework.*;
public class Xalan2Transformer 
  extends AbstractActor 
  implements org.apache.cocoon.transformer.Transformer, Status
    public Document transform(Document in, String inBase, 
        Document sheet, String sheetBase, 
        Document out, Dictionary params)
        throws Exception {
        DOMSource sheetSrc = new DOMSource(sheet);
        TransformerFactory tFactory = TransformerFactory.newInstance();
        javax.xml.transform.Transformer transformer = tFactory.newTransformer(sheetSrc);
        //transformer.setURIResolver(new XalanURIResolver());
        Enumeration enum = params.keys();
        while (enum.hasMoreElements()) {
            String name = (String)enum.nextElement();
            String value = (String)params.get(name);
            transformer.setParameter(name, value);
        DOMSource inSrc = new DOMSource(in);
        DOMResult transformResult = new DOMResult(out);
        transformer.transform(inSrc, transformResult);
        return out;
    public String getStatus()
        return "Xalan2 XSLT Processor";
This successfully allows Cocoon to transform a document that has its <?cocoon-process type="xslt"?>
and <?xml-stylesheet ...etc.?> processing instructions present that points to an XSL
document to transform into the response. I have a few files that use the XPath document()
function to load external documents into variables that worked with Xalan 1.2.x and seem broken
with 2.x. For example:
<!-DocumentToTransform.xml -->
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="Stylesheet.xsl"?>
<!-- ImportedDocument.xml -->
<someotherdata someattrib="value"/>
<!-Stylesheet.xsl -->
<xsl:stylesheet xmlns:xsl= <>
            <xsl:variable name="importedDoc" select="document('ImportedDocument.xml')/someotherdata"/>
            <xsl:template match="/">
                                    <title><xsl:value-of select="$importedDoc/@someattrib"/></title>
Previously (assuming these 3 files are in the same directory and "DocumentToTransform.xml"
is requested from a browser) this scenario would produce the HTML doc with the title being
the value of the "someattrib" attribute from the imported doc. The error I get during transformation
(PathToFile)/Stylesheet.xsl; Line 0; Column 0; Can not load requested doc: Namespace not supported
by SAXParser
I have tried writing my own URIResolver class and got it to open the correct file and pass
it to TRaX but I get the same error, leading me to believe it is a bug in Xalan and not the
TRaX API or Xalan's ability to locate files imported with the document() function. It seems
rather to be another bug related to files parsed after location when retrieved via the document()
I'm not sure what is causing this however I'm looking forward to functional document() function
support when it becomes available.
Jayme Edwards
Rockwell Software

View raw message