|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Multiple Conditions in <xsl:if> and <xsl:for-each>
Is it possible to place multiple conditions in an <xsl:if> statement? If so, can this also be done in <xsl:for-each>?
I want to filter out xml based on 3 conditions. I've managed to get it working beautifully based on one condition, but there doesn't seem to be an AND keyword in XSL. I'm aware I could embed my <xsl:if> but with the <xsl:for-each> it wouldn't work. The code is below. Any suggestions? Code:
<xsl:for-each select='//SuiteSummary/Environment[OS=$OS]'> |
|
#2
|
|||
|
|||
|
The answer to your question is rather easy
![]() What you have to know is that in XSLT, the IF..THEN..ELSE structure doesn't exist. You can only test IF a condition is true, and take action based on that. If have more than one possible value in your test, you have to use the xsl:choose element, which acts a bit like a SWITCH..CASE (or SELECT .. CASE depending on the language). xsl:choose must be used like this: Code:
<xsl:choose> <xsl:when test="any test in here"> ... action ... </xsl:when> <xsl:when test="any test in here"> ... action ... </xsl:when> <xsl:when test="any test in here"> ... action ... </xsl:when> <xsl:otherwise> ... action ... </xsl:otherwise> </xsl:choose> you can have as many xsl:when elements as you want (I'm not aware of any limit to be honest).. but if you end up with a large number of tests, then you probably have to review your code and the way your data are structured in XML. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Multiple Conditions in <xsl:if> and <xsl:for-each> |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|