[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Another tokenize() question

Subject: RE: Another tokenize() question
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 11 Aug 2004 11:02:02 +0100
regular expression tokenize
> <xsl:analyze-string regex="{[^{}]*}" select="$lines">

The regex should be written

regex = "[^{{}}]*"

No outer curlies, because this is an AVT attribute, and curlies are used to
enclose XPath expressions.

Similarly the inner curlies must be doubled to stop them being treated as
AVT curlies that introduce XPath expressions.

Michael Kay



> <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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.