Reputation: 15
Hi I need to concat a xsl node path with a variable to have a dinamic node path in xslt.
I have this node:
<PRODOTTI>
<ITEM STATO="2">
</PRODOTTI>
<STATI>
<COD0>Errore</COD0>
<COD1>In spedizione entro le prossime 12-24 ore</COD1>
<COD2>In spedizione entro le prossime 24-48 ore</COD2>
</STATI>
and in xsl I have
<xsl:variable name="stato_ordine" select="@STATO"/>
<xsl:variable name="ordine" select="concat(../../../TRADUZIONI/STATI/COD, $stato_ordine)" />
<xsl:value-of select="$ordine"></xsl:value-of>
but in output I only get the "stato_ordine" value, instead i'd need the complete path to get the node value.
Is there anyway to have this?
Thank you.
Upvotes: 1
Views: 1540
Reputation: 167436
I think you want <xsl:value-of select="../../../TRADUZIONI/STATI/*[local-name() = concat('COD', $stato_ordine)]"/>
.
[edit]
For a more efficient solution you could define a key as a child of xsl:stylesheet
<xsl:key name="k1" match="STATI/*[starts-with(local-name(), 'COD')]" use="substring(local-name(), 4)"/>
and then doing
<xsl:value-of select="key('k1', $stato_ordine)"/>
should suffice.
Upvotes: 3