Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:key name="kContentByElName" match="Localization/Content/*" use="name()"/&gt; &lt;xsl:key name="kNestedById" match="Localization/Content/Nested/NestedItem" use="Id"/&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="/*/Content/*[not(self::Nested)]/text()"&gt; &lt;xsl:variable name="vTranslation" select="key('kContentByElName', name(..))"/&gt; &lt;xsl:value-of select="$vTranslation | self::node()[not($vTranslation)]"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match= "NestedItem[not(ancestor::Localization)]/Content/text()"&gt; &lt;xsl:variable name="vTranslation" select="key('kNestedById', ../../Id)/Content"/&gt; &lt;xsl:value-of select="$vTranslation | self::node()[not($vTranslation)]"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Localizations"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document</strong>:</p> <pre><code>&lt;Page&gt; &lt;Id&gt;Page1&lt;/Id&gt; &lt;Content&gt; &lt;Header&gt;This is the Header&lt;/Header&gt; &lt;Body&gt;This is the body&lt;/Body&gt; &lt;Nested&gt; &lt;NestedItem&gt; &lt;Id&gt;N1&lt;/Id&gt; &lt;Content&gt;This is a nested element&lt;/Content&gt; &lt;/NestedItem&gt; &lt;NestedItem&gt; &lt;Id&gt;N2&lt;/Id&gt; &lt;Content&gt;This too is a nested element&lt;/Content&gt; &lt;/NestedItem&gt; &lt;/Nested&gt; &lt;/Content&gt; &lt;Localizations&gt; &lt;Localization&gt; &lt;Locale&gt;ES&lt;/Locale&gt; &lt;Content&gt; &lt;Header&gt;Esta un caballo&lt;/Header&gt; &lt;Body&gt;Esta body&lt;/Body&gt; &lt;Nested&gt; &lt;NestedItem&gt; &lt;Id&gt;N2&lt;/Id&gt; &lt;Content&gt;Esta una element nestado&lt;/Content&gt; &lt;/NestedItem&gt; &lt;/Nested&gt; &lt;/Content&gt; &lt;/Localization&gt; &lt;/Localizations&gt; &lt;/Page&gt; </code></pre> <p><strong>produces the wanted, correct result</strong>:</p> <pre><code>&lt;Page&gt; &lt;Id&gt;Page1&lt;/Id&gt; &lt;Content&gt; &lt;Header&gt;Esta un caballo&lt;/Header&gt; &lt;Body&gt;Esta body&lt;/Body&gt; &lt;Nested&gt; &lt;NestedItem&gt; &lt;Id&gt;N1&lt;/Id&gt; &lt;Content&gt;This is a nested element&lt;/Content&gt; &lt;/NestedItem&gt; &lt;NestedItem&gt; &lt;Id&gt;N2&lt;/Id&gt; &lt;Content&gt;Esta una element nestado&lt;/Content&gt; &lt;/NestedItem&gt; &lt;/Nested&gt; &lt;/Content&gt; &lt;/Page&gt; </code></pre> <p><strong>Do note</strong>:</p> <ol> <li><p>This is a pure XSLT 1.0 solution.</p></li> <li><p>Keys are used for fast searching.</p></li> <li><p>All nodes are copied "as-is" by using the <em>identity rule</em>.</p></li> <li><p>Templates matching the nodes that need processing override the identity rule.</p></li> <li><p>Whenever there is no translation found the original text is preserved.</p></li> </ol>
 

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