下面的代码可以按预期工作,并且当文本中存在Internet时,它将被匹配。
<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>
当行:
<xsl:analyze-string select="$text" regex="(.*)(Internet)(.*)" flags="m">
替换为:
<xsl:analyze-string select="$text" regex="$matchedRegex" flags="m">
它不再与正则表达式匹配。我确实需要将其作为参数传递。反正有做这项工作吗?
最佳答案
使用属性值模板
regex="{$matchedRegex}"
关于regex - 当正则表达式为变量时,analyzer-string不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7667541/