This works for me: it gives the result
<?xml version="1.0" encoding="UTF-8"?><result><root><a/><a/><a/></root><count>3</count></result>
This is running with Saxon
Saxon 8.6.1 is by now rather an old release.
Secondly, Saxon only recognizes DOM nodes if saxon8-dom.jar (bzw. saxon9-dom.jar) is on the classpath. Without this Jar on the classpath, Saxon 9.0 fails like this:
Error on line 1
  XPTY0019: Required item type of first operand of '/' is node(); supplied value has item
However, I get the results you report if I run it on 8.6.1 with saxon8-dom.jar on the classpath. So it seems you need to upgrade. If that's not possible for some reason, another option might be to wrap the Document object in a DOMSource and supply that as the parameter value. (JAXP incidentally leaves it entirely implementation-defined what kinds of object are accepted as parameters; there's no intrinsic reason to believe that anything that works with Xalan will work with Saxon or vice versa.)
Michael Kay

From: [] On Behalf Of Hedenus, Michael (EXT)
Sent: 25 January 2008 13:50
Subject: [saxon] Transformer.setParameter(Document) does not work

Dear All,
if I pass a W3C Document node to Transformer.setParameter( ) (Saxon 8.6.1) it actually behaves inside the stylesheet as the node of the root element,
or it doesn't work at all. I am using only standard APIs? If you use Xalan (2.7.0) it works as expected.
Here is an example code:
1) create a document that will be passed as parameter
2) simple stylesheet that takes itself as input
3) evaluate content of xsl:param
public static void main(String[] args) throws Exception
  // the document parameter
  DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
  Document mydoc = documentBuilder.parse(new InputSource(new StringReader("<root><a/><a/><a/></root>")));
  // the stylesheet
  String xsl=
  "<xsl:stylesheet version='2.0' xmlns:xsl=''>"
  + "  <xsl:output method='xml' encoding='UTF-8'/>"
  + "  <xsl:param name='mydoc'/>"
  + ""
  + "  <xsl:template match='/'>"
  + "    <result>"
  + "      <xsl:copy-of select='$mydoc'/>"
  + "      <count><xsl:value-of select='count($mydoc/root/a)'/></count>"
  + "    </result>"
  + "  </xsl:template>"
  + "</xsl:stylesheet>";
  //String  factoryClassName = "org.apache.xalan.processor.TransformerFactoryImpl";
  String factoryClassName = "net.sf.saxon.TransformerFactoryImpl";
  TransformerFactory transformerFactory = (TransformerFactory)Class.forName(factoryClassName).newInstance();
  Transformer transformer = transformerFactory.newTransformer(new StreamSource(new StringReader(xsl)));
  transformer.setParameter("mydoc", mydoc);
  transformer.transform(new StreamSource(new StringReader(xsl)), new StreamResult(System.out));
The result is:
<?xml version="1.0" encoding="UTF-8"?><result><count>0</count></result>
In contrast Xalan:
<?xml version="1.0" encoding="UTF-8"?><result><root><a/><a/><a/></root><count>3</count></result>
Mit den besten Gruessen/Best regards,

Dr. Michael Hedenus

VDO Automotive AG
Siemensstrasse 12, 93055 Regensburg, Germany

Ein Unternehmen des Continental-Konzerns/A Company of the Continental Corporation

Telefon/Phone: +49 941 790-6362
Telefax: +49 941 79013-6362

VDO Automotive AG, Siemensstr. 12, 93055 Regensburg
Postfach/Postbox 10 09 43, 93009 Regensburg
Vorsitzender des Aufsichtsrats/Chairman of the Supervisory Board: Johannes Suttmeyer
Vorstand/Managing Board: Dr. Alan Hippe, Helmut Matschi
Sitz der Gesellschaft/Registered office: Regensburg
Registergericht/Commercial registry: Regensburg, HRB 10510


Proprietary and confidential. Distribution only by express authority of Continental AG or its subsidiaries.