title: XSL query tag based on value
body: <p>XML Input:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
      &lt;output&gt;
          &lt;calls&gt;
              &lt;call&gt;
                  &lt;parameters&gt;
                      &lt;parameter name="id"&gt;CTL-000002&lt;/parameter&gt;
                  &lt;/parameters&gt;
                  &lt;Results&gt;
                      &lt;ex id="1"&gt;
                          &lt;column name="CFGCapacity"&gt;9500.0000000&lt;/column&gt;
                          &lt;column name="CFGCode"&gt;CTL-3819&lt;/column&gt;
                          &lt;column name="CPCode"&gt;CTL-3819-01&lt;/column&gt;
                          &lt;column name="CPCapacity"&gt;2700&lt;/column&gt;
                          &lt;column name="unit"&gt;gallon&lt;/column&gt;
                      &lt;/ex&gt;
                      &lt;ex id="2"&gt;
                          &lt;column name="CFGCapacity"&gt;52120.0000000&lt;/column&gt;
                          &lt;column name="CFGCode"&gt;CTL-3819&lt;/column&gt;
                          &lt;column name="CPCode"&gt;CTL-3819-01&lt;/column&gt;
                          &lt;column name="CPCapacity"&gt;22950&lt;/column&gt;
                          &lt;column name="unit"&gt;pound&lt;/column&gt;
                      &lt;/ex&gt;
                      &lt;ex id="3"&gt;
                          &lt;column name="CFGCapacity"&gt;9500.0000000&lt;/column&gt;
                          &lt;column name="CFGCode"&gt;CTL-3819&lt;/column&gt;
                          &lt;column name="CPCode"&gt;CTL-3819-02&lt;/column&gt;
                          &lt;column name="CPCapacity"&gt;1700&lt;/column&gt;
                          &lt;column name="unit"&gt;gallon&lt;/column&gt;
                      &lt;/ex&gt;
                  &lt;/Results&gt;
              &lt;/call&gt;
          &lt;/calls&gt;
      &lt;/output&gt;
      &lt;plant&gt;
          &lt;id&gt;CTL-000002&lt;/id&gt;
          &lt;plant_tag&gt;0&lt;/plant_tag&gt;
      &lt;/plant&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>XSL:</p>
  
  <pre><code>&lt;xsl:template match="@* | node()"&gt;
      &lt;root&gt;
          &lt;xsl:for-each select="//plant"&gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test="plant_tag='0'"&gt;
                      &lt;cfgs&gt;
                          &lt;cfg&gt;
                              &lt;id&gt;
                                  &lt;xsl:value-of select="//root/output/calls/call/parameters[parameter[@name='id'] = ./id]/../../Results/ex/column[@name='CFGCode']"/&gt;
                              &lt;/id&gt;
                          &lt;/cfg&gt;
                      &lt;/cfgs&gt;
                      &lt;xsl:copy-of select="."/&gt;
                  &lt;/xsl:when&gt;
                  &lt;xsl:otherwise&gt;
                      &lt;!--smthing else--&gt;
                  &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
          &lt;/xsl:for-each&gt;
      &lt;/root&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I am not sure what I am doing wrong.<br>
  Basically, I want to insert in cfg/id tag the value from the column with the name 'CFGCode'. The trick is that I may have different 'calls' with different parameters, so I want to make sure i populate the ID tag with the correct value, that's why i am trying to match the plant/ID with the parameter[name='id'] from the call.
  If those values match, then select the value from CFGCode.</p>
  
  <p>The final objective is that, i have multiple 'plants' tags, with different information, and I need to match the plant ID with the one from the 'call' in order to select some info from my call results (these are some results from a query).</p>
  
  <p>Thank you!</p>
  
  <p>Edit:</p>
  
  <p>Expected Output:</p>
  
  <pre><code>&lt;root&gt;
  &lt;plant&gt;
      &lt;cfgs&gt;
          &lt;cfg&gt;
              &lt;id&gt;CTL-3819&lt;/id&gt;
          &lt;/cfg&gt;
      &lt;/cfgs&gt;
      &lt;id&gt;CTL-000002&lt;/id&gt;
      &lt;plant_tag&gt;0&lt;/plant_tag&gt;
  &lt;/plant&gt;
  &lt;/root&gt;
  </code></pre>