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

Re: case conversion with replace() (i.e., with a regul

Subject: Re: case conversion with replace() (i.e., with a regular expression)
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 26 Jul 2020 21:54:23 -0000
Re:  case conversion with replace() (i.e.
On 26.07.2020 23:34, Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx
wrote:

I need to convert the first character of a string from lower-case to
upper-case. I know that I can do so with the following code:

concat(upper-case(substring(.,1,1)),substring(.,2))

I was wondering whether it can also be done with the replace() function,
i.e., with a regular expression. I found out that some regular
expression versions have the command \u for that. So I tried the following:

replace(.,'^(.)','\u$1')

But this produces an error with Saxon ("FORX0004: Invalid replacement
string in replace(): \ character must be followed by \ or $"). Does this
mean that case conversion is not available in the regular expression
version implemented in XSLT? Or did I get the code wrong?

It is not supported as far as I know, if you really want to break up the string with a regular expression then in XPath/XSLT 3 you can use fn:analyze-string

('abc' => analyze-string('^(.)'))!(upper-case(*:match) || *:non-match)

although for that simple example of identifying the first character that
looks rather convoluted to me.

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.