Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>XSL cannot <em>replace</em> anything. The best you can do is to copy the parts you want to keep, then output the parts you want to change instead of the parts you don't want to keep.</p> <hr> <p>Example:</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;!-- This is an identity template - it copies everything that doesn't match another 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;!-- This is the "other template". It says to use your BBB-DDD elements instead of the AAA element --&gt; &lt;xsl:template match="criterion[.='AAA']"&gt; &lt;xsl:element name="criterion"&gt; &lt;xsl:text&gt;BBB&lt;/xsl:text&gt; &lt;/xsl:element&gt; &lt;xsl:element name="criterion"&gt; &lt;xsl:text&gt;CCC&lt;/xsl:text&gt; &lt;/xsl:element&gt; &lt;xsl:element name="criterion"&gt; &lt;xsl:text&gt;DDD&lt;/xsl:text&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <hr> <p>The template match <code>@* | node()</code> matches any attribute or any other kind of node. The trick is that template matches have priorities. You can think of the rule as being "the more specific match wins". <em>Anything</em> is going to be more specific than "any attribute or other node". This makes the "identity" match a very low priority.</p> <p>When it <em>is</em> matched, it simply copies any nodes it finds inside the matched attribute or node. </p> <p>Any other templates you have will have a higher priority. Whatever they match, it's the code inside the more specific template that will have effect. For example, if you simply removed everything inside of the <code>criterion[.='AAA']</code> template, you'd find that you had copied your input exactly, except for the "AAA" element.</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