xsl-list
[Top] [All Lists]

Re: [xsl] construct dynamic replacement value in replace()?

2017-10-30 12:51:18
On 30.10.2017 18:47, Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de wrote:
On 30.10.2017 18:33, Birnbaum, David J djbpitt(_at_)pitt(_dot_)edu wrote:

The desired output would be '11 Tim. 14:133', that is, each sequence of digits would be regarded as a discrete decimal numerical value, captured as the match with '$0', and passed to the local:stuff() function, where it would be converted to a number. augmented by 10, converted back to a string (since the replacement part of the replace() function must be a string), and returned. The actual output, alas, is 'NaN Tim. NaN:NaN'. Before I give up and do it in XSLT, I would be grateful for any pointers toward an XPath or XQuery solution.

XPath 3.1 can do it with analyze-string:

let $initial := '1 Tim. 4:123'
return string-join(analyze-string($initial, '[0-9]+')/*!(if (local-name() eq 'match') then . + 10 else string()))

Perhaps that element check is better implemented as

let $initial := '1 Tim. 4:123'
return string-join(analyze-string($initial, '[0-9]+')/*!(if (. instance of element(fn:match)) then . + 10 else string()))

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>