Analy-string does not match when regex is a variable

The code below works as expected, and when the Internet is present in the text, it is matched.

<xsl:template name="IndexTerm"> <xsl:param name="matchedRegex"> <xsl:text>(.*)(Internet)(.*)</xsl:text> </xsl:param> <xsl:param name="text"></xsl:param> <xsl:analyze-string select="$text" regex="(.*)(Internet)(.*)" flags="m"> <xsl:matching-substring> <xsl:call-template name="IndexTerm"> <xsl:with-param name="text"> <xsl:value-of select="regex-group(1)"></xsl:value-of> </xsl:with-param> </xsl:call-template> <xsl:element name="a"> <xsl:attribute name="id"> <xsl:value-of select="generate-id($text)"></xsl:value-of> </xsl:attribute> <xsl:value-of select="regex-group(2)"></xsl:value-of> </xsl:element> <xsl:value-of select="regex-group(3)"></xsl:value-of> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."></xsl:value-of> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template> 

when line:

 <xsl:analyze-string select="$text" regex="(.*)(Internet)(.*)" flags="m"> 

replaced by:

 <xsl:analyze-string select="$text" regex="$matchedRegex" flags="m"> 

it no longer matches the regular expression. I need to pass it as a parameter. Is there any way to make this work?

+6
source share
1 answer

Use attribute value pattern

 regex="{$matchedRegex}" 
+8
source

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


All Articles