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: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 22 Mar 2025 13:00:01 -0000
On 22/03/2025 13:03, 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.


In functx it is implemented: https://www.datypic.com/xsl/functx_replace-first.html

<xsl:function name="functx:replace-first" as="xs:string"
B B B B B B B B B B B B B  xmlns:functx="http://www.functx.com";>
B  <xsl:param name="arg" as="xs:string?"/>
B  <xsl:param name="pattern" as="xs:string"/>
B  <xsl:param name="replacement" as="xs:string"/>

B  <xsl:sequence select="
B B  replace($arg, concat('(^.*?)', $pattern),
B B B B B B B B B B B B  concat('$1',$replacement))
B "/>

</xsl:function>

Current Thread