Note that there are some explanatory texts on larger screens.

plurals
  1. POMaintaining XML comments during XSL Transformations
    primarykey
    data
    text
    <p>XML</p> <pre><code>&lt;?xml-stylesheet type="text/xsl" href="script.xsl"?&gt; &lt;elements&gt; &lt;stack&gt; &lt;name&gt;Ray&lt;/name&gt; &lt;status&gt;0&lt;/status&gt; &lt;/stack&gt; &lt;!-- Comment 1 --&gt; &lt;things&gt; &lt;!-- Comment 2 --&gt; &lt;thing&gt; &lt;color&gt;red&lt;/color&gt; &lt;!-- State Comment --&gt; &lt;state&gt;solid&lt;/state&gt; &lt;!-- Weight Comment --&gt; &lt;weight&gt;45&lt;/weight&gt; &lt;unit&gt;34&lt;/unit&gt; &lt;!-- Comment 3 --&gt; &lt;/thing&gt; &lt;/things&gt; &lt;favs&gt; &lt;stick&gt;ready&lt;/stick&gt; &lt;!-- Comment 4--&gt; &lt;/favs&gt; &lt;/elements&gt; </code></pre> <p>EXPECTED OUTPUT</p> <pre><code>&lt;elements&gt; &lt;stack&gt; &lt;name&gt;Ray&lt;/name&gt; &lt;status&gt;0&lt;/status&gt; &lt;/stack&gt; &lt;!-- Comment 1 --&gt; &lt;mainElements&gt; &lt;!-- Comment 2 --&gt; &lt;specialThing&gt; &lt;!-- Weight Comment --&gt; &lt;PropertyOne&gt;45&lt;/PropertyOne&gt; &lt;PropertyTwo&gt;red&lt;/PropertyTwo&gt; &lt;!-- State Comment --&gt; &lt;PropertyThree&gt;solid&lt;/PropertyThree&gt; &lt;/specialThing&gt; &lt;!-- Comment 3 --&gt; &lt;/mainElements&gt; &lt;favs&gt; &lt;stick&gt;ready&lt;/stick&gt; &lt;!-- Comment 4--&gt; &lt;/favs&gt; &lt;/elements&gt; </code></pre> <p>CURRENT XSL </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="things"&gt; &lt;mainElements&gt; &lt;xsl:apply-templates select="thing"/&gt; &lt;/mainElements&gt; &lt;/xsl:template&gt; &lt;xsl:template match="thing"&gt; &lt;specialThing&gt; &lt;xsl:apply-templates select="weight"/&gt; &lt;xsl:apply-templates select="color"/&gt; &lt;xsl:apply-templates select="state"/&gt; &lt;/specialThing&gt; &lt;/xsl:template&gt; &lt;xsl:template match="weight"&gt; &lt;PropertyOne&gt; &lt;xsl:value-of select="."/&gt; &lt;/PropertyOne&gt; &lt;/xsl:template&gt; &lt;xsl:template match="color"&gt; &lt;PropertyTwo&gt; &lt;xsl:value-of select="."/&gt; &lt;/PropertyTwo&gt; &lt;/xsl:template&gt; &lt;xsl:template match="state"&gt; &lt;PropertyThree&gt; &lt;xsl:value-of select="."/&gt; &lt;/PropertyThree&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>I was not able to indent the output properly as i mentioned in the output. But the main thing i want to achieve is to maintain the comments of the tags which are maintained in the output.</p> <p>eg: the tag named weight is renamed to "PropertyOne" and the value is also maintained in the output. But the comment above the same is missing. I want to keep the comment of the same in the output also. How can i achieve that?</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