Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're using a <code>soap12</code> namespace prefix in your output. You should declare this in the root of your stylesheet, like so:</p> <pre><code>&lt;xsl:stylesheet ... xmlns:soap12="someuri" ...&gt; </code></pre> <p>It's also possible that the stylesheet doesn't actually output anything if the input root can't be matched against any template, or outputs an invalid XML file. The latter could be the case if you've got both a <code>Payload</code> and <code>Payload2</code> element in your XML somewhere, but its root element doesn't match any template.</p> <p>You might want to consider using named templates and calling those, instead of using <code>apply-templates</code> with something that might also match out of context. Or use template modes to make sure you're only using a template from within another one.</p> <p>EDIT: take a look at this XML...</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;test&gt; &lt;Payload/&gt; &lt;Payload2/&gt; &lt;/test&gt; </code></pre> <p>Applying your stylesheet to it (with corrected <code>soap12</code> declaration) would yield the following:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"&gt; &lt;soap12:Body&gt; &lt;Method1&gt; &lt;xdocPayload&gt; &lt;Payload/&gt; &lt;/xdocPayload&gt; &lt;/Method1&gt; &lt;/soap12:Body&gt; &lt;/soap12:Envelope&gt; &lt;soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"&gt; &lt;soap12:Body&gt; &lt;Method2&gt; &lt;xdocPayload&gt; &lt;Payload2/&gt; &lt;/xdocPayload&gt; &lt;/Method2&gt; &lt;/soap12:Body&gt; &lt;/soap12:Envelope&gt; </code></pre> <p>That ain't valid XML since there's two root elements, which isn't allowed.</p> <p>Here's a suggested reworking of your stylesheet:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" exclude-result-prefixes="msxsl"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="/Envelope" priority="2"&gt; &lt;soap12:Envelope&gt; &lt;xsl:apply-templates select="Payload"/&gt; &lt;/soap12:Envelope&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/Request1" priority="2"&gt; &lt;soap12:Envelope&gt; &lt;xsl:apply-templates select="Payload"/&gt; &lt;/soap12:Envelope&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/Request2" priority="2"&gt; &lt;soap12:Envelope&gt; &lt;xsl:apply-templates select="Payload2"/&gt; &lt;/soap12:Envelope&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/*" priority="1"&gt; &lt;soap12:Envelope /&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Payload"&gt; &lt;soap12:Body&gt; &lt;Method1&gt; &lt;xdocPayload&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@* | node()"/&gt; &lt;/xsl:copy&gt; &lt;/xdocPayload&gt; &lt;/Method1&gt; &lt;/soap12:Body&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Payload2"&gt; &lt;soap12:Body&gt; &lt;Method2&gt; &lt;xdocPayload&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@* | node()"/&gt; &lt;/xsl:copy&gt; &lt;/xdocPayload&gt; &lt;/Method2&gt; &lt;/soap12:Body&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Mind that I don't have a full picture of your input or desired output, so don't simply take the above literally but look at what it does and correct according to your own requirements.</p> <p><strong>EDIT 2:</strong> okay, after you've added the samples it's clearer what you want to do. You'll need to simply call named templates, like I suggested earlier. Here's a basis to get started from. Adapt as you see fit, make sure you test various input cases. Find an editor program somewhere that let's you quickly try out or even debug XSLT, it'll help a great deal:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" exclude-result-prefixes="msxsl"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="/Envelope" priority="2"&gt; &lt;soap12:Envelope&gt; &lt;xsl:call-template name="Payload"/&gt; &lt;/soap12:Envelope&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/Request1" priority="2"&gt; &lt;soap12:Envelope&gt; &lt;xsl:call-template name="Payload"/&gt; &lt;/soap12:Envelope&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/Request2" priority="2"&gt; &lt;soap12:Envelope&gt; &lt;xsl:call-template name="Payload2"/&gt; &lt;/soap12:Envelope&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/*" priority="1"&gt; &lt;soap12:Envelope /&gt; &lt;/xsl:template&gt; &lt;xsl:template name="Payload"&gt; &lt;soap12:Body&gt; &lt;Method1&gt; &lt;xdocPayload&gt; &lt;xsl:copy-of select="." /&gt; &lt;/xdocPayload&gt; &lt;/Method1&gt; &lt;/soap12:Body&gt; &lt;/xsl:template&gt; &lt;xsl:template name="Payload2"&gt; &lt;soap12:Body&gt; &lt;Method2&gt; &lt;xdocPayload&gt; &lt;xsl:copy-of select="." /&gt; &lt;/xdocPayload&gt; &lt;/Method2&gt; &lt;/soap12:Body&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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