sarma
sarma

Reputation: 63

how to simplify xslt 'when' condition with multiple or conditions in it?

in my xslt code, i need to have a condition like below

<xsl:when test="$CreditCardType ='SWITCH' 
                and 
                ($ccLength =16 
                 or $ccLength =18 
                 or $ccLength =19)">
  <xsl:value-of select="true()"/>
</xsl:when>

<xsl:when test="$firstFourDigits ='5018' 
                or $firstFourDigits ='5020' 
                or $firstFourDigits ='5038' 
                or $firstFourDigits ='6304' 
                or $firstFourDigits ='6759' 
                or $firstFourDigits ='6761' 
                or $firstFourDigits ='6763'">
  <xsl:value-of select="'MAESTRO'"/>
</xsl:when>

Is there anyway, i can avoid those multiple or conditions, simplify the code, like below?

<xsl:when test="$firstFourDigits ='5018' | '5020' | '5038' | '6304' | '6759' | '6761'| '6763'">
                        <xsl:value-of select="'MAESTRO'"/>
                    </xsl:when>

Upvotes: 1

Views: 232

Answers (1)

Jirka Š.
Jirka Š.

Reputation: 3428

In xslt 2.0 you could make this

test="$firstFourDigits = 
      ('5018', '5020', '5038', '6304', '6759', '6761', '6763')"

In xslt 1.0 you could probably use concat() and contains() function

contains(concat('5018|', '5020|', '5038|', 
         '6304|', '6759|', '6761|', '6763|'), 
          concat($firstFourDigits, '|'))

Upvotes: 2

Related Questions