switch case in XSL

gacon picture gacon · Aug 3, 2009 · Viewed 38.9k times · Source

I have a loop with the same tags to load content in ten cells but has a difference div title and background image, so I wonder is there any way to use the switch case just to put correct div title when I do for-each to load content for each cells in XSL? something like this: <...load the same tags content here...> Please help me because I'm new in XSL, and thank you in anyway!!

Answer

gef picture gef · Aug 3, 2009

You may use the if condition

<xsl:if test="expression">
  ...some output if the expression is true...
</xsl:if>

or choose, if there's more than one condition to check

<xsl:choose>
  <xsl:when test="expression">
    ... some output ...
  </xsl:when>
  <xsl:when test="another expression">
    ... some output ...
  </xsl:when>
  <xsl:otherwise>
    ... some output ....
  </xsl:otherwise>
</xsl:choose>