Re: [F&O] regular expressions: non-capturing groups

[note this is not a response from a WG member]

In this case you don't need non capturing groups, you can just grab all
potential keywords (eg [a-z]+) in the analyze-string, then test to see
what you have before deciding whether to add the keyword markup, eg
changing your code to
<xsl:template match="programlisting[@role='pseudocode']/text()">
  <xsl:analyze-string select="."  regex="[a-z]+">
    <xsl:matching-substring>
       <xsl:choose>
      <xsl:when test=". = ('while','true','if','else','end')">
      <span class="keyword">
        <xsl:copy-of select="."/>
      </span>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy-of select="."/>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:matching-substring>
    <xsl:non-matching-substring>
      <xsl:copy/>
    </xsl:non-matching-substring>
  </xsl:analyze-string>
</xsl:template>

produces:

bash-2.05b$ java -jar saxon8.jar in.dbx through.xslt 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
      <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8"/>
   <title>Some Code</title><link rel="stylesheet" href="style.css" type="text/css" /></head><body><div>
  <h1>Some Code</h1>
  
  <pre><code class="pseudocode">
  <span class="keyword">while</span>  <span class="keyword">true</span>  foo 
  <span class="keyword">while</span> <span class="keyword">true</span>  foo 
</code></pre>
</div></body></html>bash-2.05b$ 



David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Received on Tuesday, 23 November 2004 11:03:10 UTC