I have 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 the java method:
public static String echo(String a) { System.out.println("HERE I AM:"+a+":"); return "<xxx>" + a + "</xxx>"; }
If I have only the following snippet:
<GOGO> <xsl:copy-of select="response"/> </GOGO>
transformation of the result will look like this:
<foo>val1</foo> <bar>val2</bar>
However, when calling the Java method, logging out is displayed unexpectedly:
val1 val2
What am I doing wrong and how do I get the java method to output the expected xml fragment?
EDIT: Answer questions from those who help me: I use Saxon9. Someone from another thread showed me the use of value-of and disable-output-escaping = "yes", which allowed me to print the element tag xxx in the output. However, I'm still a dead end on the input side, where I would like my java class to have a full understanding of the full xml fragment that I passed to it.
The foo and bar tags are the xml that I want to pass to the java function. Inside the java function, I want to wrap xml in the xxx tag even more.
EDIT 2: The hints below allowed me to get 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; }
source share