Note that there are some explanatory texts on larger screens.

plurals
  1. POProcessing only selected nodes
    text
    copied!<p>An XSLT-newbie problem: I need to substitute a text value in XML-file. All other nodes must be left unchanged. Here's my input file (in.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;root&gt; &lt;level1 attr1="val1"&gt; &lt;level2&gt;in&lt;/level2&gt; &lt;/level1&gt; &lt;/root&gt; </code></pre> <p>Here's my XSLT-transformation (subst.xsl):</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:template match="/"&gt; &lt;xsl:apply-templates /&gt; &lt;/xsl:template&gt; &lt;xsl:template match="//node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates /&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/root/level1/level2/text()"&gt;out&lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>I run it with the following Ant-script (build.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;project name="test" default="test" basedir="."&gt; &lt;target name="test"&gt; &lt;xslt style="subst.xsl" in="in.xml" out="out.xml" /&gt; &lt;/target&gt; &lt;/project&gt; </code></pre> <p>And here's what I get (out.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;root&gt; &lt;level1&gt; &lt;level2&gt;out&lt;/level2&gt; &lt;/level1&gt; &lt;/root&gt; </code></pre> <p>Attribute "attr1" of "level1" is missing.</p> <p>I would be very grateful if anyone</p> <ul> <li>tell me <strong>what's wrong with subst.xsl</strong></li> </ul> <p>OR</p> <ul> <li>give me an idea how to force xslt-processor <strong>just copy non-matched nodes</strong> to output file and to do it by hand (which is in my case error-prone).</li> </ul>
 

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