Reputation: 2063
I often use tricky hashmaps in xsl but this time... I have no idea on how can I solve this issue...
Relevent extract of XML :
<DOCUMENT>
<PANO_LIV_MIN>True</PANO_LIV_MIN>
<PANO_LIV_INTER>True</PANO_LIV_INTER>
<!-- PANO_LIV_MATIN voluntarily ommited -->
</DOCUMENT>
Relevent extract of XSL :
[...]
<xsl:variable name="hashmap">
<entry key="PANO_LIV_MATIN">Matin</entry>
<entry key="PANO_LIV_MIN">Ministre</entry>
<entry key="PANO_LIV_INTER">International</entry>
</xsl:variable>
<xsl:for-each select="PANO_LIV_MATIN[text() = 'True'] | PANO_LIV_MIN[text() = 'True'] | PANO_LIV_INTER[text() = 'True']">
<span class="panorama">
<xsl:value-of select="exsl:node-set($hashmap)/entry[@key=name()]" />*
#<xsl:value-of select="name()"/>#
</span>
</xsl:for-each>
[...]
Result :
<span class="panorama">* #PANO_LIV_MATIN#</span> - <span style="" class="panorama">* #PANO_LIV_MIN#</span>
Expected result :
<span class="panorama">Matin * #PANO_LIV_MATIN#</span> - <span style="" class="panorama">Ministre * #PANO_LIV_MIN#</span>
What works :
<xsl:value-of select="exsl:node-set($hashmap)/entry[@key='PANO_LIV_MATIN']" />
<!-- gives me Matin as expected -->
What not works but I don't know why :
<xsl:value-of select="exsl:node-set($hashmap)/entry[@key=name()]" />
<!-- gives me nothing, but the name() print exactly the good key if I put it in a xsl:value-of -->
What's wrong with the name()
method ?
Upvotes: 0
Views: 154
Reputation: 167716
You need <xsl:value-of select="exsl:node-set($hashmap)/entry[@key = name(current())]" />
.
Upvotes: 1
Reputation: 1645
The Problem with name()
in your example is that it is at the wrong context node, because it is used in the select on your $hashmap
you have to use a variable instead:
<xsl:for-each select="PANO_LIV_MATIN[text() = 'True'] | PANO_LIV_MIN[text() = 'True'] | PANO_LIV_INTER[text() = 'True']">
<xsl:variable name="name" select="name()"/>
<span class="panorama">
<xsl:value-of select="exsl:node-set($hashmap)/entry[@key=$name]" />*
#<xsl:value-of select="name()"/>#
</span>
Upvotes: 1