I have read a lot of post and tried a lot of things but still can\'t get the xsl to find values in the parameter. I started with java\'s sun xalan and never got it working
When you use the JAXP interface, the values you can supply for parameters are not defined in the API specification, and Saxon's support may differ from Xalan's. Generally I think you will find that Saxon's s9api interface is much easier to use. Certainly its methods for supplying parameters are strongly typed and it's much clearer what you can supply. If you want to supply a node, it should be an instance of XdmNode, and you can create an XdmNode by parsing lexical XML using a s9api DocumentBuilder, or by wrapping a DOM Node.
I was able to get it work with Saxon see below code. I think the key was the document.getDocumentElement() as parm
public String transformResultXML(String xmlSource, Templates xsl,String policyXml ) {
String result = "";
try {
StringWriter writer = new StringWriter();
StringReader reader2 = new StringReader(policyXml);
DocumentBuilderFactory dfactory =
DocumentBuilderFactory.newInstance( "com.icl.saxon.om.DocumentBuilderFactoryImpl",null);
dfactory.setNamespaceAware(true);
DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
org.w3c.dom.Document document = docBuilder.parse(new InputSource(new StringReader(xmlSource)));
Transformer transformer = xsl.newTransformer();
transformer.setParameter("RsXml", document.getDocumentElement());
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(new javax.xml.transform.stream.StreamSource(reader2),
new javax.xml.transform.stream.StreamResult(writer));
result = writer.toString();
System.out.println(result);
} catch( Exception e ) {
e.printStackTrace();
}
XSL snippet
<xsl:param name="RsXml" />
<xsl:template match="/policy/vehicles">
<xsl:for-each select="$RsXml/InsuranceSvcRs/com.csc_PolicyOrderCurrentCarrierInqRs/PersVeh">
When you pass a parameter to an XSL stylesheet, the value is a string and is not parsed into a DOM. This is not currently possible in standard XSLT. There may be an extension that will do this but I'm not aware of one.