Search code examples
xpathesbmessagebroker

concatenate a string/character n number of times in xpath


I am using a mapping node in my messageflow and there is a part where i need to conatenate a string/character n times in xpath function. Is there any way to do this with some xpath expression or xpath build function (or both) ? for example: concatenate '~' 17 times.


Solution

  • Easy in XPath 2.0:

    string-join(for $i in 1 to 17 return '~', '')
    

    Easier still in XPath 3.0:

    string-join((1 to 17)!'~')
    

    In XPath 1.0 your best bet is probably to initialize a variable $tildes with 100 (or however many) tildes, and then use

    substring($tildes, 1, 17)