Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

analyze-string does not match when regex is a variable

The Code Below works as expected and when Internet is present in the text it gets 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 the line:

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

is replaced with:

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

it no longer matches the regex. I do need to pass it in as a param. Is there anyway to make this work?

like image 493
claybo.the.invincible Avatar asked Oct 05 '11 20:10

claybo.the.invincible


1 Answers

Use an attribute value template

regex="{$matchedRegex}"
like image 166
Michael Kay Avatar answered Oct 15 '22 15:10

Michael Kay