Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This OP has conceiled the most important fact about the XML document</strong> -- as he tells us in a later comment, "<em>The XML uses a namespace</em>" ...</p> <p><strong>Here is a solution to this so late-clarified question</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="some:namespace" xmlns="some:namespace" exclude-result-prefixes="x"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&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="x:F"&gt; &lt;G&gt; &lt;xsl:apply-templates/&gt; &lt;/G&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when this transformation is applied on the following XML document</strong> (based on the namespace the OP admitted...):</p> <pre><code>&lt;T xmlns="some:namespace"&gt; &lt;A&gt; &lt;B&gt; &lt;/B&gt; &lt;C&gt; &lt;/C&gt; &lt;/A&gt; &lt;D&gt; &lt;E&gt;Data&lt;/E&gt; &lt;F&gt;Data&lt;/F&gt; &lt;/D&gt; &lt;/T&gt; </code></pre> <p><strong>the wanted, correct result is produced</strong>:</p> <pre><code>&lt;T xmlns="some:namespace"&gt; &lt;A&gt; &lt;B /&gt; &lt;C /&gt; &lt;/A&gt; &lt;D&gt; &lt;E&gt;Data&lt;/E&gt; &lt;G&gt;Data&lt;/G&gt; &lt;/D&gt; &lt;/T&gt; </code></pre> <p><strong>Explanation</strong>:</p> <p>The problem in the original code is here:</p> <pre><code> &lt;xsl:template match="F"&gt; </code></pre> <p>This template matches an element <code>F</code> that is in no namespace. However all elements of the real XML document are in some undisclosed namespace -- not in no namespace. Therefore, the above template cannot match an <code>F</code> element in no namespace, because no such (<code>F</code> element in no namespace) exists.</p> <p>The solution is to define the same namespace in the XSLT transformation and to have the template match an <code>F</code> element in that namespace.</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.
 

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