XSLT - substring validation

I have two XSLT variables as follows:

<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 if the second line (dynamicUrl) is a substring of the first line (staticBaseUrl) or not?

+4
source share
1 answer

To check if one line 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 insensitivity, you must first convert two strings to the same register 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> 
+18
source

Source: https://habr.com/ru/post/1344066/


All Articles