Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding XML piece to an existing XML using XSLT
    text
    copied!<p>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.</p> <p>My input XML :</p> <pre><code> &lt;input xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="nbA2.8.90.xsd"&gt; &lt;nodeA id="test"&gt; &lt;inodeAA&gt; Sample &lt;/inodeAA&gt; &lt;inodeAB&gt; Samples &lt;/inodeAB&gt; &lt;/nodeA&gt; &lt;nodeB id="test"&gt; &lt;inodeBA&gt; Sample &lt;/inodeBA&gt; &lt;inodeBB&gt; Samples &lt;/inodeBB&gt; &lt;/nodeB&gt; &lt;/input&gt; </code></pre> <p>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:</p> <pre><code> &lt;ns3:output xmlns:ns3="http://mysample.org"&gt; &lt;ns3:reply id="rep"&gt; &lt;ns3:zip&gt;55555&lt;/ns3:zip&gt; &lt;ns3:place&gt;SampleLoc&lt;/ns3:place&gt; &lt;/ns3:reply&gt; &lt;/ns3:output&gt; </code></pre> <p>Below is my Expected Output:</p> <pre><code> &lt;input xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="nbA2.8.90.xsd"&gt; &lt;nodeA id="test"&gt; &lt;inodeAA&gt; Sample &lt;/inodeAA&gt; &lt;inodeAB&gt; Samples &lt;/inodeAB&gt; &lt;/nodeA&gt; &lt;nodeB id="test"&gt; &lt;inodeBA&gt; Sample &lt;/inodeBA&gt; &lt;inodeBB&gt; Samples &lt;/inodeBB&gt; &lt;/nodeB&gt; &lt;ns3:output xmlns:ns3="http://mysample.org"&gt; &lt;ns3:reply id="rep"&gt; &lt;ns3:zip&gt;55555&lt;/ns3:zip&gt; &lt;ns3:place&gt;SampleLoc&lt;/ns3:place&gt; &lt;/ns3:reply&gt; &lt;/ns3:output&gt; &lt;/input&gt; </code></pre> <p>Below is the XSL I am using for this task:</p> <p>In the below XSLT the param "outParam" holds the xml piece which I am trying to add to me input.</p> <pre><code> &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns3="http://mysample.org" exclude-result-prefixes="soap xsl"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes" /&gt; &lt;xsl:param name="outParam"&gt;&lt;/xsl:param&gt; &lt;xsl:template match="input"&gt; &lt;input&gt; &lt;xsl:copy-of copy-namespaces="no" select="./@*" /&gt; &lt;xsl:copy-of copy-namespaces="no" select="node() | @*" /&gt; &lt;/input&gt; &lt;xsl:copy &gt; &lt;xsl:value-of select="$outParam" disable-output-escaping="yes" &gt;&lt;/xsl:value-of&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Below is the output I am getting. This is not matching my expected output.</p> <pre><code> &lt;input xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="http://mysample.org" xsi:noNamespaceSchemaLocation="nbA2.8.90.xsd" &gt; &lt;nodeA id="test"&gt; &lt;inodeAA&gt; Sample &lt;/inodeAA&gt; &lt;inodeAB&gt; Samples &lt;/inodeAB&gt; &lt;/nodeA&gt; &lt;nodeB id="test"&gt; &lt;inodeBA&gt; Sample &lt;/inodeBA&gt; &lt;inodeBB&gt; Samples &lt;/inodeBB&gt; &lt;/nodeB&gt; &lt;/input&gt; &lt;input xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;ns3:output xmlns:ns3="http://mysample.org"&gt; &lt;ns3:reply id="rep"&gt; &lt;ns3:zip&gt;55555&lt;/ns3:zip&gt; &lt;ns3:place&gt;SampleLoc&lt;/ns3:place&gt; &lt;/ns3:reply&gt; &lt;/ns3:output&gt; &lt;/input&gt; </code></pre> <p>Please help. I have tried many combinations but no luck. :(</p> <p>Note: I am performing this transformation using the Mule XSLT Transformer which transforms payload XML based on the XSLT provided.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload