I think the problem is not with the regex, but with the contents of the xsl:matching-substring element. At this point the context item is a string, and the <xsl:copy> should copy this string; the child element within the xsl:copy is ignored.
You haven't actually said what's happening, so I don't know if this is enough to explain the syptoms you are observing. And I'm not sure what you're trying to achieve, so I can't suggest a replacement.
As a matter of interest, Saxon 8.1 detects this error in your code at compile time: it reports
Saxon 8.1 from Saxonica
Java version 1.4.1_02
Error on line 24 of file:/c:/temp/test.xsl:
  Cannot use an axis here: the context item is an atomic value
Failed to compile stylesheet. 1 error detected.
where line 24 is the line:
 <xsl:apply-templates select="@*|element()"/>

Michael Kay
Saxonica Limited

Was this advice useful? If you benefit from the help given, especially on a commercial project, you can help us to continue to provide this service by making a donation. See http://sourceforge.net/project/project_donations.php?group_id=29872 

From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Schochler, Richard E
Sent: 27 September 2004 21:48
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Acceptable values within regex attr of xsl:analyze-string

I'm trying to replace an older perl-based program with xslt. Succinctly put, our docs are authored as composite works, which are split up according to *country code attributes* at run time. If an element doesn't have a country code, it's assumed that it applies to all countries. These country code values are held within semi-colon delimited values (if needed) within the attribute:

  <para id="d0e207" country.code="BA-CG;USAF-A;USAF-AM;USAF-C">Misc. information stuff.</para>
  <para id="d0e208" country.code="USAF-A">More content</para>

I pass the country code when the xslt is run, via a global param. I am attempting to use <xsl:analyze-string> to test for the existence of the string within the country.code attribute. Here's my template:

<xsl:template match="@*|element()">
  <xsl:when test="not(@COUNTRY.CODE)">
      <xsl:apply-templates select="@*|element()"/>
  <xsl:when test="self::*[@COUNTRY.CODE]">
    <xsl:variable name="ccValue">
      <xsl:value-of select="self::*/@COUNTRY.CODE"/>
   <xsl:analyze-string select="$ccValue" regex="/{$countryCode}\W/">
         <xsl:apply-templates select="@*|element()"/>
     <xsl:non-matching-substring><!-- do nothing --></xsl:non-matching-substring>

Passing in the countryCode value within curly-braces is not working. I've tried doubling the braces. Any suggestions?