xslt - Display different image depending on xml output using xsl -


i have xml (that external part) outputs:

...<prop name="day">monday</prop> <prop name="week">2</prop>... 

i wondering if @ possible use xsl display image instead of name of day? name of day change 7 possible variables , need show different image each day of week.

so result i'm hoping this:

 <img src="mondayimage.jpg">  <p>week number 2</p> 

in xslt 2.0 van use index-of xpath function generate efficient lookup:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0">     <xsl:output indent="yes"/>      <xsl:param name="days" select="('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday')"/>     <xsl:param name="day-image" select="('image1.png','image2.png','image3.png','image4.png','image5.png','image6.png','image7.png')"/>      <xsl:template match="/root">         <root>             <xsl:apply-templates/>         </root>     </xsl:template>      <xsl:template match="prop[@name='day']">         <img src="{$day-image[index-of($days, current())]}"/>     </xsl:template>      <xsl:template match="prop[@name='week']">         <p>week number <xsl:value-of select="."/></p>     </xsl:template> </xsl:transform> 

working example


Comments