Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>It is possible to create XPath expressions dynamically in XSLT, but no dynamic evaluation of these expressions is possible (at least until <a href="http://www.w3.org/TR/2010/WD-xslt-21-20100511/#element-evaluate" rel="nofollow noreferrer">XSLT 2.1</a>).</strong></p> <p>What you want can be done in another way in XSLT. </p> <p><strong>Here is an example:</strong></p> <p>This transformation:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="my:my" &gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;my:criteria&gt; &lt;criterion&gt;a&lt;/criterion&gt; &lt;criterion&gt;b&lt;/criterion&gt; &lt;criterion&gt;c&lt;/criterion&gt; &lt;/my:criteria&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="*[name()=document('')/*/my:criteria/*]"&gt; &lt;xsl:element name="{name()}-{name()}" namespace="{namespace-uri()}"&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on this XML document</strong>:</p> <pre><code>&lt;t&gt; &lt;a&gt; &lt;x/&gt; &lt;y/&gt; &lt;b&gt; &lt;c/&gt; &lt;d/&gt; &lt;/b&gt; &lt;/a&gt; &lt;/t&gt; </code></pre> <p><strong>produces</strong>:</p> <pre><code>&lt;t&gt; &lt;a-a&gt; &lt;x&gt;&lt;/x&gt; &lt;y&gt;&lt;/y&gt; &lt;b-b&gt; &lt;c-c&gt;&lt;/c-c&gt; &lt;d&gt;&lt;/d&gt; &lt;/b-b&gt; &lt;/a-a&gt; &lt;/t&gt; </code></pre> <p><strong>That is, we only processed in a special way any element (anywhere in the document), whose name was <code>a</code> or <code>b</code> or <code>c</code>.</strong></p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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