Applying XSLT transformation removes element names
Issue
Before transferring messages from a SOAP endpoint to a next step, we need to apply a transformation over it to wrap the current body in another element. We have used an XSLT transformation for this. This XSLT transformation is picked up, and it returns the wrapping element, but the original body has its element names removed. The rest of the original body is intact.
The route:
<route id="cxf-to-queue">
<from uri="cxf:bean:endpoint?dataFormat=PAYLOAD" ></from>
<choice>
<when>
<simple>${in.header.operationName} == 'operation'</simple>
<log message="Original body: ${in.body}" ></log>
<to uri="xslt:classpath:xslt/wrap.xslt" ></to>
<log message="Transformed: ${in.body}" ></log>
<inOnly uri="activemq:QUEUE.NAME?jmsMessageType=Text" ></inOnly>
<transform>
<constant><![CDATA[<voidResponse ></voidResponse>]]></constant>
</transform>
</when>
</choice>
</route>
The XSLT content:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output media-type="text/xml" indent="yes" ></xsl:output>
<xsl:template match="/">
<message>
<header>
<subsidiary>xxx</subsidiary>
<initiator>yyy</initiator>
<target>zzz</target>
</header>
<payload>
<xsl:copy-of select="." ></xsl:copy>
</payload>
</message>
</xsl:template>
</xsl:stylesheet>
With an original body of "
If I try this same XSLT and this same input in a standalone program that uses javax.xml.transform.Transformer, the result is exactly as expected.
As a reference, the code using Transformer:
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.xml.sax.InputSource;
public class XSLTTest {
public static void main(String[] args) throws Exception {
Transformer transformer = TransformerFactory.newInstance().newTransformer(new SAXSource(new InputSource(XSLTTest.class.getResourceAsStream("/test.xslt"))));
Source xmlSource = new StreamSource(XSLTTest.class.getResourceAsStream("/input.xml"));
Result outputTarget = new StreamResult(System.out);
transformer.transform(xmlSource, outputTarget);
}
}
Are we missing something?
Environment
- JBoss Fuse 6.1
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
