title: Variable in XSLT 3 with conditioning that returns the node name attribute if its child node contains specific name attribute
body: <p>I would like to create a variable that will only be filled/populated if the child node of my node <code>config</code> has a specific name, in this case <code>deviceName</code>.</p>
  <p>Here is an example of my input file:</p>
  <pre><code>&lt;configs&gt;
      &lt;config name=&quot;CFAAI_CFA2&quot; extends=&quot;CFAAI&quot; abstract=&quot;true&quot;&gt;
           &lt;param name=&quot;deviceName&quot;&gt;CFA2&lt;/param&gt;
      &lt;/config&gt;
  &lt;/configs&gt;
  </code></pre>
  <p>And here is the code I have so far for the variable:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;xsl:stylesheet
      xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;3.0&quot;&gt;
      &lt;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; indent=&quot;no&quot; /&gt;
  
      &lt;xsl:template match=&quot;@*|node()&quot;&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select=&quot;@*|node()&quot; /&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
  
  &lt;xsl:template match=&quot;config&quot;&gt;
          &lt;xsl:text&gt;&amp;#10;&amp;#9;&amp;#9;&lt;/xsl:text&gt;
          &lt;xsl:copy-of select=&quot;.&quot; /&gt;
          &lt;xsl:variable name=&quot;namePrefix&quot; &gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test=&quot;/param[@name='deviceName']&quot;&gt;
                      &lt;xsl:value-of select=&quot;config/@name&quot;/&gt;
                  &lt;/xsl:when&gt;
              &lt;/xsl:choose&gt;
          &lt;/xsl:variable&gt;
          &lt;xsl:if
              test=&quot;not(contains(@name, 'TRANSFER') or contains(@extends, 'TRANSFER'))&quot;&gt;
              &lt;xsl:if
                  test=&quot;count(. | //configs/config[starts-with(@name, $namePrefix)][1]) &amp;lt;= 1&quot;&gt;
                  &lt;xsl:if test=&quot;not(contains(@name, 'production'))&quot;&gt;
                      &lt;xsl:apply-templates select=&quot;.&quot;
                          mode=&quot;create_production&quot;&gt;
                          &lt;xsl:with-param name=&quot;productionName&quot;
                              select=&quot;concat($namePrefix, '_production')&quot; /&gt;
                      &lt;/xsl:apply-templates&gt;
                  &lt;/xsl:if&gt;
              &lt;/xsl:if&gt;
          &lt;/xsl:if&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p>But my code is currently returning me an empty variable.</p>
  <p>I would like my code to check if the attribute <code>name</code> of the child node <code>/param</code> equals <code>deviceName</code> and if it does I would like to select and return the value of its parent (the <code>config</code> node) <code>name</code> attribute.</p>
  <p>Any suggestions on how could I do that inside a variable?</p>