Re: [xsl] Another tokenize() question

Subject: Re: [xsl] Another tokenize() question
From: James Cummings <James.Cummings@xxxxxxxxxxxxxx>
Date: Wed, 11 Aug 2004 10:46:51 +0100 (BST)
On Wed, 11 Aug 2004, David Carlisle wrote:


Ok, in attempting David's method:

> Then do your main ana-whatist-thingy, making sure anything inside
> braces, ie "{[^{}]*}" is part of the "word" regexp
<snip/>
> except that instead of using value-of in the matching-substring part
> where you are adding <w> do another nested analyaze-strang and match on  
> "{([a-z]*) ([^{}])*}

I get:
------------
<xsl:template match="l/text()">
<xsl:variable name="lines">
<xsl:apply-templates mode="a" />
</xsl:variable>
<xsl:analyze-string regex="{[^{}]*}" select="$lines">
<xsl:matching-substring>
<w><xsl:analyze-string regex="{([a-z]*) ([^{}])*}">
                <xsl:matching-substring>
                <xsl:element name="{regex-group(1)}">
                 <xsl:value-of select="regex-group(2)"/>
                </xsl:element>
                </xsl:matching-substring>
        <xsl:non-matching-substring>
        <xsl:value-of select="."/>
        </xsl:non-matching-substring>
</xsl:analyze-string></w></xsl:matching-substring>
<xsl:non-matching-substring><xsl:value-of select="."/></xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
------------

Which I'm sure must be wrong because saxon gives me:
----------
saxon -o temp2.xml temp.xml addwords2.xsl
Error at xsl:analyze-string on line 29 of file: addwords2.xsl:
  Invalid character '^' in expression
Error at xsl:analyze-string on line 29 of file: addwords2.xsl:
  Error in regular expression:
net.sf.saxon.type.RegexTranslator$RegexSyntaxException: Error
  at character 0 in regular expression: expected end of string
Error at xsl:analyze-string on line 30 of file: addwords2.xsl:
  Element must have a "select" attribute
Error at xsl:analyze-string on line 30 of file: addwords2.xsl:
  XPath syntax error in {{([a-z}:
    Unexpected token "[" in path expression
Error at xsl:analyze-string on line 30 of file: addwords2.xsl:
  Error in regular expression:
net.sf.saxon.type.RegexTranslator$RegexSyntaxException: Error
  at character 0 in regular expression: expected end of string
Transformation failed: Failed to compile stylesheet. 5 errors detected.
----------

Which I'm sure I've created by not adding the regex properly
in the word regex.  Should that be {\w+[^{}]*}  or something?

I've always had a difficult time with regular expressions...

-James
---
Dr James Cummings, Oxford Text Archive, University of Oxford
James dot Cummings at oucs dot ox dot ac dot uk 
CALL FOR PAPERS: Digital Medievalism (Kalamazoo) and 
Early Drama (Leeds) see http://users.ox.ac.uk/~jamesc/cfp.html

Current Thread