Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please give this a try:</p> <pre><code>&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:param name="fileName" select="'update.xml'" /&gt; &lt;xsl:param name="updates" select="document($fileName)" /&gt; &lt;xsl:variable name="updateEmployees" select="$updates/employees/employee" /&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="employees"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="employee[not(@id = $updateEmployees/@id)]" /&gt; &lt;xsl:apply-templates select="$updateEmployees" /&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>When run with your first XML as the input and with the update.xml present in the same folder, this produces:</p> <pre><code>&lt;employees&gt; &lt;employee id="1"&gt; &lt;name&gt; Name1 &lt;/name&gt; &lt;email&gt; email1 &lt;/email&gt; &lt;/employee&gt; &lt;employee id="2"&gt; &lt;name&gt; Name2 &lt;/name&gt; &lt;email&gt; email_New &lt;/email&gt; &lt;/employee&gt; &lt;employee id="3"&gt; &lt;name&gt; Name3 &lt;/name&gt; &lt;email&gt; email3 &lt;/email&gt; &lt;/employee&gt; &lt;/employees&gt; </code></pre> <p><code>fileName</code> and <code>updates</code> are declared as parameters, so if the updates are in a file named something other than "update.xml" or you want to pass the update XML in directly, you can do that without making any modifications to the XSLT.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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