Thursday, 19 November 2009

XML, XSLT - Equivalent CASE statement in XSLT

 1: <poem author="jm" year="1667">
 2:  <verse>Seest thou yon dreary Plain, forlorn and wild,</verse>
 3:  <verse>The seat of desolation, void of light,</verse>
 4:  <verse>Save what the glimmering of these livid flames</verse>
 5:  <verse>Casts pale and dreadful?</verse>
 6: </poem>
 7:  
 8: <xsl:template match="poem">
 9:  
 10:  <xsl:choose>
 11:  <xsl:when test="@year < 1638">
 12:  The poem is one of Milton's earlier works.
 13:  </xsl:when>
 14:  
 15:  <xsl:when test="@year < 1650">
 16:  The poem is from Milton's middle period.
 17:  </xsl:when>
 18:  
 19:  <xsl:when test="@year < 1668">
 20:  The poem is one of Milton's later works.
 21:  </xsl:when>
 22:  
 23:  <xsl:when test="@year < 1675">
 24:  The poem is one of Milton's last works.
 25:  </xsl:when>
 26:  
 27:  <xsl:otherwise>
 28:  The poem was written after Milton's death.
 29:  </xsl:otherwise>
 30:  
 31:  </xsl:choose>
 32:  
 33: </xsl:template>

No comments: