Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>This XSLT 1.0 stylesheet ...</strong></p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:esl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="xsl esl" &gt; &lt;xsl:output indent="yes" omit-xml-declaration="yes" /&gt; &lt;xsl:strip-space elements="*" /&gt; &lt;xsl:key name="kByName" match="*" use="local-name()" /&gt; &lt;xsl:variable name="DefaultNodes"&gt; &lt;DefaultNodes&gt; &lt;a&gt;-1&lt;/a&gt; &lt;b&gt;-1&lt;/b&gt; &lt;c&gt;-1&lt;/c&gt; &lt;d&gt;-1&lt;/d&gt; &lt;/DefaultNodes&gt; &lt;/xsl:variable&gt; &lt;xsl:template match="Message"&gt; &lt;MsgHead&gt; &lt;Document&gt; &lt;xsl:copy&gt; &lt;xsl:variable name="union"&gt; &lt;xsl:apply-templates select="* | esl:node-set($DefaultNodes)/DefaultNodes/*[local-name()]"/&gt; &lt;/xsl:variable&gt; &lt;xsl:copy-of select="esl:node-set($union)/*[generate-id() = generate-id(key('kByName',local-name())[1])]" /&gt; &lt;/xsl:copy&gt; &lt;/Document&gt; &lt;/MsgHead&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:stylesheet&gt; </code></pre> <p><strong>... when applied to this input document ...</strong></p> <pre><code>&lt;Message&gt; &lt;a&gt;123&lt;/a&gt; &lt;c&gt;456&lt;/c&gt; &lt;d&gt;789&lt;/d&gt; &lt;/Message&gt; </code></pre> <p><strong>... yields ...</strong></p> <pre><code>&lt;MsgHead&gt; &lt;Document&gt; &lt;Message&gt; &lt;a&gt;123&lt;/a&gt; &lt;c&gt;456&lt;/c&gt; &lt;d&gt;789&lt;/d&gt; &lt;b&gt;-1&lt;/b&gt; &lt;/Message&gt; &lt;/Document&gt; &lt;/MsgHead&gt; </code></pre> <p>Note: Change the esl namespace to <code>http://exslt.org/common</code> as required, depending on your XSLT processor.</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