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='http://www.w3.org/1999/XSL/Transform'>"
  + "  <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
SV P EG 1
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
E-Mail: Michael.Hedenus-EXT@continental-corporation.com
http://www.continental-corporation.com
__________________________________________

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.