Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your approach with <code>&lt;xsl:result-document&gt;</code> is perfectly sound. The only problem is that your stylesheet is XSLT 1, and for <code>&lt;xsl:result-document&gt;</code> you need XSLT 2. XSLT being a functional language has nothing to do with this problem.</p> <p>If necessary, post your XSLT code that uses <code>&lt;xsl:result-document&gt;</code> and I'll fix it for you.</p> <p>Edit:</p> <p>Here your code with the necessary changes. Parts of your original code such as <code>method="text"</code> indicate you want the result to be a text file, while <code>&lt;xsl:element&gt;</code> looks like you're trying to output an XML file, so I wrote code for both. As mentioned before, <code>&lt;xsl:result-document&gt;</code> requires XSLT 2.</p> <p>This creates an XML file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:variable name="foldername" select="concat(/build/major, /build/minor, string(/build/build + 1), build/release)"/&gt; &lt;xsl:result-document href="{$foldername}/foo.xml" method="xml"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:copy&gt; &lt;/xsl:result-document&gt; &lt;/xsl:template&gt; &lt;xsl:template match="element()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/build/build"&gt; &lt;xsl:copy&gt; &lt;xsl:variable name="buildNumber" select="."/&gt; &lt;xsl:value-of select="$buildNumber + 1"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>And this creates a text file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="text"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:variable name="foldername" select="concat(/build/major, /build/minor, string(/build/build + 1), build/release)"/&gt; &lt;xsl:result-document href="{$foldername}/foo.txt" method="text"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:result-document&gt; &lt;/xsl:template&gt; &lt;xsl:template match="element()"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/build/build"&gt; &lt;xsl:variable name="buildNumber" select="."/&gt; &lt;xsl:value-of select="$buildNumber + 1"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>The output file is created in a folder whose name is the version, as you wanted, but note the folder must exist beforehand.</p>
 

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