Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Here is a more generic solution</strong>. The names of the elements can be specified separately from the code:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="my:my" exclude-result-prefixes="my"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;my:newValues&gt; &lt;element1&gt;Changed1&lt;/element1&gt; &lt;element2&gt;Changed2&lt;/element2&gt; &lt;element3&gt;Changed3&lt;/element3&gt; &lt;/my:newValues&gt; &lt;xsl:variable name="vElements" select="document('')/*/my:newValues/*"/&gt; &lt;xsl:template match="*" name="identity" mode="copy"&gt; &lt;xsl:element name="{name()}"&gt; &lt;xsl:copy-of select="namespace::*[not(name()='my' or name()='xsl')]"/&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*"&gt; &lt;xsl:if test="not($vElements[name()=name(current())])"&gt; &lt;xsl:call-template name="identity"/&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;xsl:template match="group"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()"/&gt; &lt;xsl:apply-templates select="$vElements" mode="copy"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when this transformation is applied on the provided XML document</strong>:</p> <pre><code>&lt;root&gt; &lt;group&gt; &lt;element1&gt;SomeValue1&lt;/element1&gt; &lt;element2&gt;SomeValue2&lt;/element2&gt; &lt;/group&gt; &lt;/root&gt; </code></pre> <p><strong>the wanted, correct result is produced</strong>:</p> <pre><code>&lt;root&gt; &lt;group&gt; &lt;element1&gt;Changed1&lt;/element1&gt; &lt;element2&gt;Changed2&lt;/element2&gt; &lt;element3&gt;Changed3&lt;/element3&gt; &lt;/group&gt; &lt;/root&gt; </code></pre> <p><strong>Note</strong>: The seemingly complicated processing that discards the <code>"xsl"</code> anf <code>"my"</code> namespaces is unnecessary when the to-be-modified elements are in their separate document. This code intentionally puts the to-be-modified elements in the same document as the xslt stylesheet for demonstration purposes. In practice, just an <code>&lt;xsl:copy-of select="$vModifiedDoc/*"&gt;</code> will be used.</p>
    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. 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