如何简化xslt'何时'条件有多个或条件?

时间:2013-08-14 19:15:46

标签: xslt xslt-1.0

在我的xslt代码中,我需要有一个类似下面的条件

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

无论如何,我可以避免那些多重或条件,简化代码,如下所示?

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

1 个答案:

答案 0 :(得分:2)

在xslt 2.0中你可以做到这个

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

在xslt 1.0中,您可以使用concat()contains()函数

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