首页 > 解决方案 > 测试包含在 XSLT 1.0 中使用不区分大小写的匹配

问题描述

如果值存在于我发送的 appName 中,我有以下匹配条件,它用于获取结果:

  <xsl:if test="contains($appName , $value)">
                        <xsl:call-template name="formResponseBody">
                        </xsl:call-template>
  </xsl:if>

但是,现在我必须进行完全相同的测试,但忽略“$value”中数据的情况。

我试过使用翻译函数,但它们要么转换为大写,要么转换为小写,但我的测试用例是数据是一个值,可以是“TEST”、“test”、“TestT”。

<xsl:variable name="lowercase">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="uppercase">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:variable name="value1" select="translate($value, $uppercase, $lowercase)"> 

这在 XSLT 1.0 中可行吗?

标签: xsltxpathxslt-1.0

解决方案


$appName将and规范化$value为大写或小写,然后测试 normalized 是否$appName包含 normalized $value

<xsl:if test="contains(
                translate($appName, $uppercase, $lowercase) , 
                translate($value, $uppercase, $lowercase))">

推荐阅读