XSLT - Checking for a substring

匿名 (未验证) 提交于 2019-12-03 03:03:02

问题:

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'" />  

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

回答1:

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

Example:

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

Update:

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> 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!