Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck for different roots in transformation
    primarykey
    data
    text
    <p>I have the following xslt sheet and I am wondering if its possible to check for a certain root in an xml file? If so what is the correct xslt code needed in order to transform the xml to use a certain template? I tried with stylesheet below that I built but this threw an error complaining about invalid root. As you can make out from this stylesheet if I have a certain root in an xml file I would like to apply a certain template to it. What do you all think? </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" exclude-result-prefixes="msxsl"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="/Envelope"&gt; &lt;xsl:apply-templates select="Payload" /&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/Request1"&gt; &lt;xsl:apply-templates select="Payload"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/Request2"&gt; &lt;xsl:apply-templates select="Payload2"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Payload" &gt; &lt;soap12:Envelope &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;/soap12:Envelope&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Payload2" &gt; &lt;soap12:Envelope&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;/soap12:Envelope&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>c# Code i'm testing with:</p> <pre><code> XslCompiledTransform xslt = new XslCompiledTransform(true); xslt.Load(XmlReader.Create(new StringReader(xsltTransSheet))); </code></pre> <p>Any help greatly appreciated.</p> <p>Thanks, DND</p> <p>2 different XML Input Files:</p> <pre><code> &lt;Envelope&gt; &lt;order&gt;1280&lt;/order&gt; &lt;/Envelope&gt; </code></pre> <p>or could be</p> <pre><code> &lt;Request1&gt; &lt;item&gt;7329HH&lt;/item&gt; &lt;Request1&gt; </code></pre> <p>Desired XML Output:</p> <pre><code>&lt;soap12:Body&gt; &lt;Method1&gt; &lt;xdocPayload&gt; &lt;Envelope&gt; &lt;order&gt;1280&lt;/order&gt; &lt;/Envelope&gt; &lt;/xdocPayload&gt; &lt;/Method1&gt; &lt;/soap12:Body&gt; </code></pre> <p>or the XML Ouput would end up being</p> <pre><code> &lt;soap12:Body&gt; &lt;Method1&gt; &lt;xdocPayload&gt; &lt;Request1&gt; &lt;item&gt;7329HH&lt;/item&gt; &lt;/Request1&gt; &lt;/xdocPayload&gt; &lt;/Method1&gt; &lt;/soap12:Body&gt; </code></pre> <p>I'm looking for one or the other result depending on xml fed into xslt. Hopefully that explains it a little more thoroughly.</p>
    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.
    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