Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy XML file contents except for root node and attribute XSLT
    primarykey
    data
    text
    <p>I am working on a small XSLT file to copy the contents of an XML file and strip out the declaration and root node. The root node has an namespace attribute.</p> <p>I currently have it working except for now the namespace attribute is now being copied to the direct children nodes.</p> <p>Here is my xslt file so far, nothing big or complicated:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" omit-xml-declaration="yes" encoding="utf-8"/&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="/*"&gt; &lt;xsl:apply-templates select="node()" /&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>My input file is like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Report_Data xmlns="examplenamespace"&gt; &lt;Report_Entry&gt; &lt;Report_Date&gt; &lt;/Report_Date&gt; &lt;/Report_Entry&gt; &lt;Report_Entry&gt; &lt;Report_Date&gt; &lt;/Report_Date&gt; &lt;/Report_Entry&gt; &lt;Report_Entry&gt; &lt;Report_Date&gt; &lt;/Report_Date&gt; &lt;/Report_Entry&gt; &lt;/Report_Data&gt; </code></pre> <p>The output after the XSLT is like this:</p> <pre><code>&lt;Report_Entry xmlns="examplenamespace"&gt; &lt;Report_Date&gt; &lt;/Report_Date&gt; &lt;/Report_Entry&gt; &lt;Report_Entry xmlns="examplenamespace"&gt; &lt;Report_Date&gt; &lt;/Report_Date&gt; &lt;/Report_Entry&gt; &lt;Report_Entry xmlns="examplenamespace"&gt; &lt;Report_Date&gt; &lt;/Report_Date&gt; &lt;/Report_Entry&gt; </code></pre> <p>The problem is, every Report_Entry tag is now getting that xml namespace attribute from the root node that I removed.</p> <p>In case you were wondering, I know the output of the XSLT is not well formed. I am adding the XML declaration and a different root node name later on after the XSLT trasnformation.</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.
 

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