This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 4949 - [FO] Suggested extension to fn:replace (first match only)
Summary: [FO] Suggested extension to fn:replace (first match only)
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 3.0 (show other bugs)
Version: Working drafts
Hardware: PC Windows XP
: P2 enhancement
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-14 18:21 UTC by Don Chamberlin
Modified: 2009-10-12 22:11 UTC (History)
0 users

See Also:


Attachments

Description Don Chamberlin 2007-08-14 18:21:54 UTC
The EXSLT community (http://exslt.org/) has defined an XSLT function named 
regexp:replace() (http://exslt.org/regexp/functions/replace/index.html) 
which is similar in purpose to our function fn:replace(). The two 
functions have different signatures and slightly different semantics. 
EXSLT's regexp:replace() function supports a flag that sets its behavior 
to replace-all-matches vs. replace-first-match-only (fn:replace() 
currently supports only the first of these behaviors and has no 
corresponding flag.)

For users of the EXSLT function who wish to migrate to XQuery or XSLT 2.0, 
it would be helpful to add an additional flag to fn:replace() that 
provides similar functionality. I request that the joint working groups 
consider this additional parameter as a possible future extension to 
fn:replace().
Comment 1 Michael Kay 2007-11-16 09:33:52 UTC
Enhancement request: Recategorized under F+O version 1.1
Comment 2 Michael Kay 2009-03-06 10:30:14 UTC
I believe this requirement is satisfied by the new analyze-string() function.

For example, to wrap parentheses around the first sequence of numeric digits in a string, one could write:

let $x := analyze-string($in, '\d+')
return string-join(
  for $s in $x
  return (if ($s is $x/match[1]) then concat('(', ., ')') else string(.))

I am accordingly marking this as fixed; please feel free to reopen if you feel this is not an adequate solution to the requirement. 
Comment 3 Michael Kay 2009-10-12 22:11:35 UTC
Since the requested functionality is provided by the new analyze-string() function, I am marking this closed.