I've got an xsl snippet:
<GOGO>
<xsl:variable name="test">
<xsl:copy-of select="response"/>
</xsl:variable>
<xsl:copy-of select="javamap:echo($test)"/>
</GOGO>
This snippet calls a java method:
public static String echo(String a) {
System.out.println("HERE I AM:"+a+":");
return "<xxx>" + a + "</xxx>";
}
If I just have the following snippet:
<GOGO>
<xsl:copy-of select="response"/>
</GOGO>
the result transformation will soemthing like:
<foo>val1</foo>
<bar>val2</bar>
However when the Java method is invoked, the system out output is unexpected only printing out:
val1
val2
What am I doing wrong and how do I get java method to output the expected xml snippet?
EDIT: Answer to questions from those helping me: I am using Saxon9. Someone in another thread showed me the use of value-of and disable-output-escaping="yes" which allowed me to print out the xxx element tag in the output. However I am still stumped on the input side where I would like my java class to have full awareness of the full xml snippet I pass to it.
The foo and bar tags are the xml I want to pass into the java function. Inside the java function I want to further wrap the xml in xxx tag.
EDIT 2: Hints below allowed me to derive the following solution: public static String echo(Node a) throws Exception {
StringWriter writer = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource(a), new StreamResult(writer));
String xml = writer.toString();
return xml;
}
xxxbut your outputfooandbar.