Search code examples
xsltif-statementswitch-statementconditional-statementsxsl-choose

switch case in XSL


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!!


Solution

  • 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>
    

    Documentation is here: https://www.w3.org/TR/xslt-10/#section-Conditional-Processing-with-xsl:choose