Re: [xsl] Formatting string

Subject: Re: [xsl] Formatting string
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 16 May 2007 14:43:09 +0200
Joe Fawcett wrote:
The trouble with these is that they don't cope with expressions such as "UKBank" or "BankOfUSA". I'm trying to come up with a neat expression that does.

The trouble is that I put the space on the wrong position. I was thinking of the double capitals and it is of course easily fixed, but I didn't know the requirements well enough. For instance: "AStringToPutAFewSpacesIn" is going to give you trouble anyway:


<xsl:value-of select="replace('BankOfUSA', '(.)([A-Z]+)', '$1 $2')" />

or, perhaps prettier:
<xsl:value-of select="normalize-space(replace('BankOfUSA', '[A-Z]+', ' $0'))" />


both will output: "Bank Of USA"

Cheers,
-- Abel Braaksma

Current Thread