Re: [xsl] Replace the portion of text that matches pattern: XPath versus SNOBOL

Subject: Re: [xsl] Replace the portion of text that matches pattern: XPath versus SNOBOL
From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 22 Mar 2025 17:35:44 -0000
On Sat, 2025-03-22 at 12:03 +0000, Roger L Costello costello@xxxxxxxxx
wrote:
>
> Suppose that you want to only replace the first match, i.e., we want
> "BELANCE." I do not think that there is any way to configure the
> XPath replace() function to "Replace only the first match." Please
> correct me if I am wrong about this.

You have to prepend ^.*? to get the first match and only that one.

Yes, it would be nice to have a 1 flag to replace only the first.

liam

--
Liam Quin,B https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations: B http://www.fromoldbooks.org

Current Thread