[xquery-talk] Using functions in replacement argument with fn:replace()?

David Sewell dsewell at virginia.edu
Thu Jan 12 12:37:32 PST 2006

I may be trying inappropriately to get Perl functionality out of the
XPath 2.0 replace() function, but I'm wondering whether according to the
specs it should be possible to pass backreferences to a function in the
replacement pattern.

I can successfully do this with expected output:

   replace("abc", ".", "$0")  => "abc"

This also gives the expected output (run in both Saxon 8.6 and MarkLogic
Server, ditto for the rest of the examples):

   replace("abc", ".", upper-case("x"))  => "XXX"

but this gives unexpected output:

   replace("abc", ".", upper-case("$0")) => "abc"  [???!!!]

and this produces a run-time error:

   replace("abc", ".", upper-case($0))

Using a different function,

  replace("123", "2", string(number("2") * 2))  => "143"


  replace("123", "2", string(number("$0") * 2)) => 1NaN3

I'm not clear from the W3C XPath 2.0 documentation whether the
replacement argument of fn:replace() is supposed to be a literal
xs:string, or whether any expression evaluating to a string is


David Sewell, Editorial and Technical Manager
Electronic Imprint, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell at virginia.edu   Tel: +1 434 924 9973
Web: http://www.ei.virginia.edu/

More information about the talk mailing list