Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It seems you wanted to create your XSLT dynamic XSLT on the basis of your configuration file which is also an XML document. Have a look this exmple considering this:</p> <p><strong>configuration.xml</strong></p> <pre><code> &lt;p&gt; &lt;configuration&gt; &lt;fruitToEat&gt;yellow_curved_thing&lt;/fruitToEat&gt; &lt;mapped&gt;banana&lt;/mapped&gt; &lt;/configuration&gt; &lt;configuration&gt; &lt;fruitToEat&gt;round_thing&lt;/fruitToEat&gt; &lt;mapped&gt;tomato&lt;/mapped&gt; &lt;/configuration&gt; &lt;/p&gt; </code></pre> <p><strong>XSLT:</strong></p> <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt; &lt;xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:element name="xsl:stylesheet"&gt; &lt;xsl:attribute name="version"&gt; &lt;xsl:text&gt;1.0&lt;/xsl:text&gt; &lt;/xsl:attribute&gt; &lt;xsl:element name="xsl:template"&gt; &lt;xsl:attribute name="match"&gt; &lt;xsl:text&gt;node()|@*&lt;/xsl:text&gt; &lt;/xsl:attribute&gt; &lt;xsl:element name="xsl:copy"&gt; &lt;xsl:element name="xsl:apply-templates"&gt; &lt;xsl:attribute name="select"&gt; &lt;xsl:text&gt;node()|@*&lt;/xsl:text&gt; &lt;/xsl:attribute&gt; &lt;/xsl:element&gt; &lt;/xsl:element&gt; &lt;/xsl:element&gt; &lt;xsl:for-each select="//configuration"&gt; &lt;xsl:element name="xsl:template"&gt; &lt;xsl:attribute name="match"&gt; &lt;xsl:text&gt;configuration/fruitToEat/text()[.=&lt;/xsl:text&gt; &lt;xsl:text&gt;'&lt;/xsl:text&gt; &lt;xsl:value-of select="fruitToEat"/&gt; &lt;xsl:text&gt;']&lt;/xsl:text&gt; &lt;/xsl:attribute&gt; &lt;xsl:element name="xsl:text"&gt; &lt;xsl:value-of select="mapped"/&gt; &lt;/xsl:element&gt; &lt;/xsl:element&gt; &lt;/xsl:for-each&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>output:</strong></p> <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&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="configuration/fruitToEat/text()[.='yellow_curved_thing']"&gt; &lt;xsl:text&gt;banana&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;xsl:template match="configuration/fruitToEat/text()[.='round_thing']"&gt; &lt;xsl:text&gt;tomato&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
 

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