Hello, 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 cocoon.properties
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); sheetSrc.setSystemId(sheetBase);
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); inSrc.setSystemId(inBase); 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"?> <somedata/> <!-- ImportedDocument.xml à <someotherdata someattrib="value"/> <!-Stylesheet.xsl à <xsl:stylesheet
xmlns:xsl=http://www.w3.org/1999/XSL/Transform
version="1.0"> <xsl:variable name="importedDoc" select="document('ImportedDocument.xml')/someotherdata"/> <xsl:template match="/"> <html> <title><xsl:value-of select="$importedDoc/@someattrib"/></title> </html> </xsl:template> </xsl:stylesheet> 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 is: (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()
function. I'm not sure what is causing this however I'm
looking forward to functional document() function
support when it becomes available. Thanks, Jayme Edwards Rockwell Software |