I have a java code snippet:
public static String echo(String a) {
System.out.println("HERE I AM:"+a+":");
return "<xxx>" + a + "</xxx>";
}
called by the below xsl snippet:
<GOGO>
<xsl:variable name="test">
<xsl:copy-of select="responseStatus"/>
</xsl:variable>
<xsl:copy-of select="javamap:echo($test)"/>
</GOGO>
For some reason if xml is passed to the java method, all the element tags are dropped. on the output side if i try to return xml tags, the < and > would be converted to & lt; and & gt;
What is wrong with my snippet and how can it be fixed so it outputs XML?
EDIT (after 1st response)
Let me elaborate on the problem:
My system out output is below:
HERE I AM:
val1
val2
:
Ideally I would like my system out to be:
HERE I AM:<foo>val1</foo><bar>val2</bar>:
as you can see, the xml tags are being dropped for some reason.
here is the solution I came up with:
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;
}
Have you tried this ?