xsl:choose and select field handle
This is an open discussion with 7 replies, filed under XSLT.
Search
Can you re-post your XML, XSLT and the desired result using the code markup?
<xsl:template match="/"> <xsl:apply-templates select="/data/albums/entry"/> </xsl:template> <xsl:template match="albums/entry"> <xsl:value-of select="streetdate "/> <xsl:value-of select="artist "/> <xsl:value-of select="albumtitle "/> <xsl:value-of select="genre "/> /* selectfield - values are "german", "french", "uk", "usa" and so on */ <xsl:value-of select="language "/> /* I want to replace the values by <img src=""> - maybe somethin like this*/ <xsl:choose> <xsl:when test="??? ='german'"> <img src="image1.png"> </xsl:when> <xsl:when test="??? ='french'"> <img src="image2.png"> </xsl:when> <xsl:when test="??? ='uk'"> <img src="image3.png"> </xsl:when> <xsl:otherwise> <img src="noimage.png"> </xsl:otherwise> </xsl:choose> </xsl:template>
Is this possible?
Yes, of course:
<xsl:template match="/"> <xsl:apply-templates select="/data/albums/entry"/> </xsl:template> <xsl:template match="albums/entry"> <xsl:value-of select="streetdate "/> <xsl:value-of select="artist "/> <xsl:value-of select="albumtitle "/> <xsl:value-of select="genre "/> <xsl:value-of select="language "/> <img> <xsl:attribute name="src"> <xsl:choose> <xsl:when test="language/@handle = 'german'">image1.png</xsl:when> <xsl:when test="language/@handle = 'french'">image2.png</xsl:when> <xsl:when test="language/@handle = 'uk'">image3.png</xsl:when> <xsl:otherwise>noimage.png</xsl:otherwise> </xsl:choose> </xsl:attribute> </img> </xsl:template>
Note that I’ve rewritten the xsl:choose
-bit a little bit. It’s now making use of xsl:attribute
.
For any reason it doesn’t work. The xsl:choose shows only the xsl:otherwise.
I controlled the handles of the language entry in phpmyadmin, but everything seems to be okay.
The xsl:value-of select=”language” shows the values and handles correctly.
Okay, i found the error.
Because the handle is inserted into an item tag (selectfield) i had to add *xsl:when test=”language/item/@handle = ‘german’”>
Thank you very much for your help.
Can you post an XML snippet? Maybe phogue assumed a wrong XML structure.
:-)
Create an account or sign in to comment.
I’ve got a little problem. I don’t know how to output the handle of entry in a xsl:choose tag. I tried a lot of combinations but nothing worked.
I want to replace the entry (or handle) of an select field in the output by an img source.
How do i do this?
I need help :)