Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this (also see shorter version at the end):</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"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&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="Content"&gt; &lt;aaa&gt; &lt;xsl:apply-templates/&gt; &lt;/aaa&gt; &lt;/xsl:template&gt; &lt;xsl:template match="content1"&gt; &lt;bbb&gt; &lt;xsl:apply-templates/&gt; &lt;/bbb&gt; &lt;/xsl:template&gt; &lt;xsl:template match="first"&gt; &lt;ccc&gt; &lt;xsl:apply-templates/&gt; &lt;/ccc&gt; &lt;/xsl:template&gt; &lt;xsl:template match="second"&gt; &lt;ddd&gt; &lt;xsl:apply-templates/&gt; &lt;/ddd&gt; &lt;/xsl:template&gt; &lt;xsl:template match="third"&gt; &lt;eee&gt; &lt;xsl:apply-templates/&gt; &lt;/eee&gt; &lt;/xsl:template&gt; &lt;xsl:template match="fourth"&gt; &lt;fff&gt; &lt;xsl:apply-templates/&gt; &lt;/fff&gt; &lt;/xsl:template&gt; &lt;xsl:template match="fifth"&gt; &lt;ggg&gt; &lt;xsl:apply-templates/&gt; &lt;/ggg&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Applied to your input, this gives</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;aaa&gt; &lt;bbb&gt; &lt;ccc&gt; Hi &lt;dynVar name="abc"/&gt; All &lt;/ccc&gt; &lt;ddd&gt;this is&lt;/ddd&gt; &lt;/bbb&gt; &lt;eee&gt;input &lt;dynVar name="def"/&gt; xml content&lt;/eee&gt; &lt;fff&gt; &lt;dynVar name="ghi"/&gt; &lt;/fff&gt; &lt;ggg&gt; &lt;dynVar name="jkl"/&gt; &lt;dynVar name="mno"/&gt; &lt;/ggg&gt; &lt;/aaa&gt; </code></pre> <p>For excluding namespaces, add attribute exclude-result-prefixes="x y z" to the stylesheet element, where x, y and z are the namespaces declared additionally.</p> <p>A shorter version that achieves exactly the same, but does not have a template for each node for which the node name has to be replaced:</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" exclude-result-prefixes=""&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&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="*[name() != 'dynVar']"&gt; &lt;xsl:variable name="eltName"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="name()='Content'"&gt;aaa&lt;/xsl:when&gt; &lt;xsl:when test="name()='content1'"&gt;bbb&lt;/xsl:when&gt; &lt;xsl:when test="name()='first'"&gt;ccc&lt;/xsl:when&gt; &lt;xsl:when test="name()='second'"&gt;ddd&lt;/xsl:when&gt; &lt;xsl:when test="name()='third'"&gt;eee&lt;/xsl:when&gt; &lt;xsl:when test="name()='fourth'"&gt;fff&lt;/xsl:when&gt; &lt;xsl:when test="name()='fifth'"&gt;ggg&lt;/xsl:when&gt; &lt;xsl:otherwise&gt;error&lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:variable&gt; &lt;xsl:element name="{$eltName}"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:element&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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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