XSLT - 检查子字符串 [英] XSLT - Checking for a substring

查看:51
本文介绍了XSLT - 检查子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 XSLT 变量,如下所示:

I have two XSLT variables as given below:

<xsl:variable name="staticBaseUrl" select="'https://www.hello.com/htapi/PrintApp.asmx/getGames?contentId=id_sudoku&uniqueId="123456"&pageformat=a4'" /> 

<xsl:variable name="dynamicUrl" select="'https://www.hello.com/htapi/PrintApp.asmx/getGames'" /> 

如何检查第二个字符串(dynamicUrl)是否是第一个字符串(staticBaseUrl)的子字符串?

How to check whether the second string (dynamicUrl) is a substring of the first string (staticBaseUrl) or not?

推荐答案

要检查一个字符串是否包含在另一个字符串中,请使用 包含函数.

To check if one string is contained in another, use the contains function.

示例:

  <xsl:if test="contains($staticBaseUrl,$dynamicUrl)">
    <xsl:text>Yes!</xsl:text>
  </xsl:if>

更新:

对于不区分大小写的contains,在调用contains之前,需要先将两个字符串转换为同一个大小写.在 XSLT 2.0 中,您可以使用 upper-case 函数,但在 XSLT 1.0 中,您可以使用以下内容:

For case-insensitive contains, you need to first convert the two strings to the same case before calling contains. In XSLT 2.0 you can use the upper-case function, but in XSLT 1.0 you can use the following:

<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

<xsl:template match="/">
    <xsl:if
        test="contains(translate($staticBaseUrl,$smallcase,$uppercase), translate($dynamicUrl,$smallcase,$uppercase))">
        <xsl:text>Yes!</xsl:text>
    </xsl:if>
</xsl:template>

这篇关于XSLT - 检查子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆