XML Input:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<output>
<calls>
<call>
<parameters>
<parameter name="id">CTL-000002</parameter>
</parameters>
<Results>
<ex id="1">
<column name="CFGCapacity">9500.0000000</column>
<column name="CFGCode">CTL-3819</column>
<column name="CPCode">CTL-3819-01</column>
<column name="CPCapacity">2700</column>
<column name="unit">gallon</column>
</ex>
<ex id="2">
<column name="CFGCapacity">52120.0000000</column>
<column name="CFGCode">CTL-3819</column>
<column name="CPCode">CTL-3819-01</column>
<column name="CPCapacity">22950</column>
<column name="unit">pound</column>
</ex>
<ex id="3">
<column name="CFGCapacity">9500.0000000</column>
<column name="CFGCode">CTL-3819</column>
<column name="CPCode">CTL-3819-02</column>
<column name="CPCapacity">1700</column>
<column name="unit">gallon</column>
</ex>
</Results>
</call>
</calls>
</output>
<plant>
<id>CTL-000002</id>
<plant_tag>0</plant_tag>
</plant>
</root>
XSL:
<xsl:template match="@* | node()">
<root>
<xsl:for-each select="//plant">
<xsl:choose>
<xsl:when test="plant_tag='0'">
<cfgs>
<cfg>
<id>
<xsl:value-of select="//root/output/calls/call/parameters[parameter[@name='id'] = ./id]/../../Results/ex/column[@name='CFGCode']"/>
</id>
</cfg>
</cfgs>
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<!--smthing else-->
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
I am not sure what I am doing wrong.
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.
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).
Thank you!
Edit:
Expected Output:
<root>
<plant>
<cfgs>
<cfg>
<id>CTL-3819</id>
</cfg>
</cfgs>
<id>CTL-000002</id>
<plant_tag>0</plant_tag>
</plant>
</root>