I have a XML-Structure like this:
<TR>
<Zeile status="done">
<Typ>FUNCTION</Typ>
<Name>PressKey</Name>
</Zeile>
<Zeile status="failed">
<Typ>FUNCTION</Typ>
<Name>PressKey</Name>
</Zeile>
<Zeile status="warn">
<Typ>FUNCTION</Typ>
<Name>PressKey</Name>
</Zeile>
<Zeile status="done">
<Typ>FUNCTION</Typ>
<Name>PressKey</Name>
</Zeile>
</TR>
Now I want to get the Element with the worst status
.
The order of the status
values from best to worst:
done
ignoreFailed
ignoreExpected
passed
unknown
warn
failed
How do I approach this? At the end I want the worst status
as Integer in a variable called worst_status
and as String in the variable worst_status_string
This is what I tried (but failed because of forbidden overwriting of variables):
<xsl:variable name="statusMapping">
<statusMap>
<status key="done" value="1"/>
<status key="ignoreFailed" value="2"/>
<status key="ignoreExpected" value="3"/>
<status key="passed" value="4"/>
<status key="unknown" value="5"/>
<status key="warn" value="6"/>
<status key="failed" value="7"/>
</statusMap>
</xsl:variable>
<xsl:template match="//TR">
<xsl:variable name="worst_status" select="1"/>
<xsl:for-each select="Zeile">
<xsl:variable name="current_status" select="@status"/>
<xsl:for-each select="exslt:node-set($statusMapping)/statusMap/status">
<xsl:if test="@key = $current_status">
<xsl:if test="@value > $worst_status">
<xsl:variable name="worst_status" select="@value"/>
</xsl:if>
</xsl:if>
</xsl:for-each>
WorstStatus: <xsl:value-of select="$worst_status"/>
</xsl:for-each>
</xsl:template>