  | |  | set a Node Parameter in the Transformer class | set a Node Parameter in the Transformer class 2007-05-28 - By Giraudet de Boudemange
I have a problem with the setParameter method in the Transformer class of xalan. I want to pass a Node parameter (a DOM element), but this node is always transform in a String with the toString() method of the node. Have a look to my code:
String styleSheetURI= "AddToCatalog.xsl";
TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource(styleSheetURI));
//PARAMETER DocumentBuilderFactory dFactory =DocumentBuilderFactory.newInstance(); dFactory.setNamespaceAware(true); Document doc2 =dFactory.newDocumentBuilder().newDocument(); Element node = doc2.createElementNS("http://example.com/auction/wsdl/doXslTransform","cd");
node.appendChild(doc2.createTextNode("Text")); doc2.appendChild(node); transformer.setParameter("newCD", doc2.getDocumentElement());
//SOURCE Document docSource=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument ();
Element nodeSource=docSource.createElement("Catalog"); docSource.appendChild(nodeSource); DOMSource source=new DOMSource( nodeSource);
//RESULT DOMResult result=new DOMResult();
//TRANSFORMATION transformer.transform(source, result);
Here is my styleSheet:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dxt="http://example.com/auction/wsdl/doXslTransform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsl:param name="newCD"><dxt:cd>DefaultText</dxt:cd></xsl:param> <xsl:template match="/"> <xsl:element name="root"> <xsl:copy-of select="$newCD"/> </xsl:element> </xsl:template> </xsl:transform>
The result of the transform is: <root>[cd: null]</root>
but I would like to have: <root><cd><Text</cd></root>
If I don't set the parameter in the java program, the default value of newCD param is used, and the result is: <root><dxt:cd xmlns:dxt="http://example.com/auction/wsdl/doXslTransform">DefaultText</dxt:cd> </root>
So how can I do to pass my Node in parameter to the transformer?
Thanks
Stanislas Giraudet de Boudemange
stanislas.giraudet-de-boudemange@(protected)
|
|
 |