Subject: Re: Tokenize question: tokenize on words, spaces and punctuation
From: Suresh <suresh.chinta@xxxxxxxxx>
Date: Wed, 16 Mar 2011 22:28:07 -0400
|
In xslt 2.0:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs" version="2.0">
<xsl:output method="text"/>
<xsl:template match="/string">
('<xsl:value-of select="tokenize(.,'[\s]+')" separator="', ' ',
'"/>')
</xsl:template>
</xsl:stylesheet>
Output:
('Oh', ' ', 'what', ' ', 'a', ' ', 'great', ' ', 'day!')
Thanks.
On Wed, Mar 16, 2011 at 8:33 PM, Martin Holmes <mholmes@xxxxxxx> wrote:
>
> Hi there,
>
> This is really a question for XPath regex gurus:
>
> I need to tokenize a string of text such that words, punctuation and spaces
are split. So from this:
>
> Oh, what a great day!
>
> I need to get:
>
> ('Oh', ',', ' ', 'what', ' ', 'a', ' ', 'great', ' ', 'day', '!')
>
> I've been hacking away at this for a while, but regexps aren't my strong
suit. Can anyone help?
>
> Cheers,
> Martin
>
--
Suresh
|