Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT - Match variable element in predicate
    text
    copied!<pre><code>&lt;xsl:apply-templates select="element[child='Yes']"&gt; </code></pre> <p>Works fine but I would like to use </p> <pre><code>&lt;xsl:apply-templates select="element[$childElementName='Yes']"&gt; </code></pre> <p>so I can use a variable to specify the node.</p> <p>For example</p> <pre><code>&lt;xsl:apply-templates select="theList/entity[Central='Yes']"&gt; </code></pre> <p>works fine against:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;theList&gt; &lt;entity&gt; &lt;Business-Name&gt;Company 1&lt;/Business-Name&gt; &lt;Phone-Number&gt;123456&lt;/Phone-Number&gt; &lt;Central&gt;Yes&lt;/Central&gt; &lt;region1&gt;No&lt;/region1&gt; &lt;region2&gt;Yes&lt;/region2&gt; &lt;region3&gt;No&lt;/region3&gt; &lt;Northern&gt;No&lt;/Northern&gt; &lt;/entity&gt; &lt;entity&gt; &lt;Business-Name&gt;Company 2&lt;/Business-Name&gt; &lt;Phone-Number&gt;123456&lt;/Phone-Number&gt; &lt;Central&gt;No&lt;/Central&gt; &lt;region1&gt;Yes&lt;/region1&gt; &lt;region2&gt;No&lt;/region2&gt; &lt;region3&gt;No&lt;/region3&gt; &lt;Northern&gt;Yes&lt;/Northern&gt; &lt;/entity&gt; &lt;entity&gt; &lt;Business-Name&gt;Company 3&lt;/Business-Name&gt; &lt;Phone-Number&gt;123456&lt;/Phone-Number&gt; &lt;Central&gt;Yes&lt;/Central&gt; &lt;region1&gt;No&lt;/region1&gt; &lt;region2&gt;No&lt;/region2&gt; &lt;region3&gt;No&lt;/region3&gt; &lt;Northern&gt;No&lt;/Northern&gt; &lt;/entity&gt; &lt;entity&gt; &lt;Business-Name&gt;Company 4&lt;/Business-Name&gt; &lt;Phone-Number&gt;123456&lt;/Phone-Number&gt; &lt;Central&gt;No&lt;/Central&gt; &lt;region1&gt;No&lt;/region1&gt; &lt;region2&gt;No&lt;/region2&gt; &lt;region3&gt;No&lt;/region3&gt; &lt;Northern&gt;No&lt;/Northern&gt; &lt;/entity&gt; &lt;/theList&gt; </code></pre> <p>But I do not wish to hard code the child element name.</p> <p>Any suggestions?</p> <p>Thanks Tim for the answer:</p> <pre><code>&lt;xsl:apply-templates select="theList/entity[child::*[name()=$childElement]='Yes']" /&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