[xsl] Using parameter as regex in matches() function

Subject: [xsl] Using parameter as regex in matches() function
From: <Dave.McGovern@xxxxxxxxxxx>
Date: Thu, 29 May 2008 17:46:00 -0400
I am using XSLT 2.0 using the Altova XMLSpy 2008 built-in engine.

I am trying to use an xsl:param parameter name as my regex within a
matches() function.

I am passing the parameter in via a call to a named template as shown
here:

...
<xsl:call-template name="assign_id">
<xsl:with-param name="criteria_name"><xsl:value-of
select="."/></xsl:with-param>
</xsl:call-template>
...

Here is the called template:
...
<xsl:template name="assign_id">
<xsl:param name="criteria_name">NULL</xsl:param>
<xsl:attribute name="id"><xsl:value-of
select="document('dictionary/subselectionCriteria.xml')//dt[matches(.,$c
riteria_name)]/ancestor::dlentry/@id"/></xsl:attribute>
<xsl:value-of select="."/>
</xsl:template>
...

With the problematic part being:
//dt[matches(.,$criteria_name)]

The problem is that I want to set boundaries for my regex using the ^
and $ meta-characters.  As I am using it above, the matches() function
is behaving more like contains().

For example, if $criteria-name is set to "Reporting Group" on a
particular iteration, I am getting matches on "Reporting Group", "From
Reporting Group", "To Reporting Group", "Reporting Group Type", etc.

I want to restrict this to only match on the exact "Reporting Group"
string.

I have tried various quoting and backslash-escaping constructs to no
avail:
//dt[matches(.,'^$criteria_name$')]
//dt[matches(.,'^\$criteria_name$')]
//dt[matches(.,'^{$criteria_name}$')]

I think this may be because the same metacharacter '$' is used for both
the param name and to set the end boundary of the regex, but I'm not
sure why escaping it wouldn't work if this is the case?

Any ideas?
Thanks in advance,
Dave

Current Thread