Re: [xsl] case conversion with replace() (i.e., with a regular expression)

Subject: Re: [xsl] case conversion with replace() (i.e., with a regular expression)
From: "Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 27 Jul 2020 13:19:51 -0000
Thank you, Martin and Michael, for your replies! It is good to learn 
that what I originally had in mind is not possible, but that there are 
the other options you point out.
Best regards,
Wolfhart


On 27.07.20 06:13, Michael Kay mike@xxxxxxxxxxxx wrote:
> Saxon has introduced the extension function replace-with() which allows
>
> replace-with($in, '^.', function($x){upper-case($x)})
>
> Michael Kay
> Saxonica
>
>> On 26 Jul 2020, at 22:34, Wolfhart Totschnig 
>> wolfhart.totschnig@xxxxxxxxxxx 
>> <mailto:wolfhart.totschnig@xxxxxxxxxxx> 
>> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx 
>> <mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>> wrote:
>>
>> Dear list,
>>
>> 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?
>>
>> Thanks in advance for your help!
>> Wolfhart
>>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/2652055> 
> (by email <>)

Current Thread