Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As requested, here a stylesheet that works as follows:</p> <ul> <li>merges nodes for which at least an <strong>EMail</strong> is matching</li> <li>during merge, <strong>FirstName</strong> and <strong>SecondName</strong> are copied from the first node always</li> <li>nodes with no matching <strong>EMail</strong> are copied as is</li> <li>nodes without <strong>EMail</strong> nodes are copied as is</li> </ul> <hr> <p>[XSLT 1.0]</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output indent="yes"/&gt; &lt;xsl:key name="k_ContactsByEmail" match="CONTACTS/CONTACT" use="EMail"/&gt; &lt;xsl:template match="CONTACTS"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="CONTACT[generate-id()= generate-id(key('k_ContactsByEmail',EMail)[1])] | CONTACT[not(EMail)]"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="CONTACT"&gt; &lt;xsl:copy&gt; &lt;xsl:copy-of select="*"/&gt; &lt;xsl:copy-of select=" key('k_ContactsByEmail', EMail)/* [not(.=current()/*)] [not(self::FirstName or self::LastName or self::Customer-ID)]"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>When applied on the XML input provided in the question, it produces:</p> <pre><code>&lt;CONTACTS&gt; &lt;CONTACT&gt; &lt;Customer-ID&gt;Cus-ID3&lt;/Customer-ID&gt; &lt;FirstName&gt;Arnaaud&lt;/FirstName&gt; &lt;LastName&gt;Forestier&lt;/LastName&gt; &lt;EMail&gt;Arnaaud_Forestier201111@yahoo.fr&lt;/EMail&gt; &lt;EMail&gt;Arnaaud_Forestier201111@gmail.com&lt;/EMail&gt; &lt;/CONTACT&gt; &lt;CONTACT&gt; &lt;Customer-ID&gt;Cus-ID7&lt;/Customer-ID&gt; &lt;FirstName&gt;Aana&lt;/FirstName&gt; &lt;LastName&gt;Edwards&lt;/LastName&gt; &lt;EMail&gt;Aana.edwards@gmail.com&lt;/EMail&gt; &lt;/CONTACT&gt; &lt;CONTACT&gt; &lt;Customer-ID&gt;Cus-ID9&lt;/Customer-ID&gt; &lt;FirstName&gt;Aana_Edwards&lt;/FirstName&gt; &lt;LastName&gt;Edwards&lt;/LastName&gt; &lt;EMail&gt;Aana.edwards@yahoo.com&lt;/EMail&gt; &lt;/CONTACT&gt; &lt;CONTACT&gt; &lt;Customer-ID&gt;Cus-ID11&lt;/Customer-ID&gt; &lt;FirstName&gt;Lina&lt;/FirstName&gt; &lt;LastName&gt;Joseph&lt;/LastName&gt; &lt;EMail&gt;Lina.Joseph@aol.com&lt;/EMail&gt; &lt;/CONTACT&gt; &lt;CONTACT&gt; &lt;Customer-ID&gt;Cus-ID13&lt;/Customer-ID&gt; &lt;FirstName&gt;SandfordFrankie&lt;/FirstName&gt; &lt;LastName&gt;Frankie Sandford&lt;/LastName&gt; &lt;EMail&gt;Sandford1233@yahoo.com&lt;/EMail&gt; &lt;URL&gt;http://www.facebook.com/profile.php?id=122112487211054&lt;/URL&gt; &lt;EMail&gt;Sandford.frankie@gmail.com&lt;/EMail&gt; &lt;/CONTACT&gt; &lt;/CONTACTS&gt; </code></pre>
 

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