I am trying to add a piece of an XML to an input XML using XSLT. But the output is not coming as expected. Pelase help.
My input XML :
<input xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="nbA2.8.90.xsd">
<nodeA id="test">
<inodeAA> Sample </inodeAA>
<inodeAB> Samples </inodeAB>
</nodeA>
<nodeB id="test">
<inodeBA> Sample </inodeBA>
<inodeBB> Samples </inodeBB>
</nodeB>
</input>
Below is another XML piece which I am passing as a parameter to me XSLT.
This piece is to be added to the input XML:
<ns3:output xmlns:ns3="http://mysample.org">
<ns3:reply id="rep">
<ns3:zip>55555</ns3:zip>
<ns3:place>SampleLoc</ns3:place>
</ns3:reply>
</ns3:output>
Below is my Expected Output:
<input xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="nbA2.8.90.xsd">
<nodeA id="test">
<inodeAA> Sample </inodeAA>
<inodeAB> Samples </inodeAB>
</nodeA>
<nodeB id="test">
<inodeBA> Sample </inodeBA>
<inodeBB> Samples </inodeBB>
</nodeB>
<ns3:output xmlns:ns3="http://mysample.org">
<ns3:reply id="rep">
<ns3:zip>55555</ns3:zip>
<ns3:place>SampleLoc</ns3:place>
</ns3:reply>
</ns3:output>
</input>
Below is the XSL I am using for this task:
In the below XSLT the param “outParam” holds the xml piece which I am trying to add to me input.
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns3="http://mysample.org"
exclude-result-prefixes="soap xsl">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:param name="outParam"></xsl:param>
<xsl:template match="input">
<input>
<xsl:copy-of copy-namespaces="no" select="./@*" />
<xsl:copy-of copy-namespaces="no" select="node() | @*" />
</input>
<xsl:copy >
<xsl:value-of select="$outParam" disable-output-escaping="yes" ></xsl:value-of>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Below is the output I am getting. This is not matching my expected output.
<input xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns3="http://mysample.org"
xsi:noNamespaceSchemaLocation="nbA2.8.90.xsd" >
<nodeA id="test">
<inodeAA> Sample </inodeAA>
<inodeAB> Samples </inodeAB>
</nodeA>
<nodeB id="test">
<inodeBA> Sample </inodeBA>
<inodeBB> Samples </inodeBB>
</nodeB>
</input>
<input xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns3:output xmlns:ns3="http://mysample.org">
<ns3:reply id="rep">
<ns3:zip>55555</ns3:zip>
<ns3:place>SampleLoc</ns3:place>
</ns3:reply>
</ns3:output>
</input>
Please help. I have tried many combinations but no luck. 🙁
Note: I am performing this transformation using the Mule XSLT Transformer which transforms payload XML based on the XSLT provided.
If the parameter is a node or sequence of nodes all you need is
If the parameter passed in is a string with XML markup then you need