Is there any XPath expression for String Padding in wso2 ESB?

孤者浪人 提交于 2019-12-04 04:56:15

问题


I have enabled XPath 2.0 configuration synapse.xpath.dom.failover.enabled=true in synapse.properties but still unable to get string padding done. Is there any expression to achieve it?

Edit :

The length of a particular string needs to be 10 chars, if it is lesser than it, we have to pad it with the special character '%'.

Eg., Input = 'WSO2', after padding it should be 'WSO2%%%%%%'

Thanks in advance


回答1:


This can be achieved using XPath 1.0 like so, assuming that "WSO2" will be replaced by dynamic input string in the actual implementation :

substring(concat('WSO2', '%%%%%%%%%%'), 1, 10)

The above XPath basically works by concatenating string of 10 specific for-padding characters to the original input string, and then substring the result to get only the first 10 characters. Found this trick in the following XSL question : XSL left-right justification with Padding

To put this in a more generic formula :

substring(concat('input_string', '%%%%....'), 1, n)
  • input_string : string to which padding operation will applied
  • % : character used for padding, repeated n times
  • n : fixed number of characters expected in the output string



回答2:


The solution from @har07 is fine if you have a reasonable upper bound on the value of n, but if you don't, you can create a string containing '%' repeated $n times using

XPath 3.0: string-join((1 to $n)!"%")

XPath 2.0: string-join(for $x in 1 to $n return "%", "")


来源:https://stackoverflow.com/questions/34174746/is-there-any-xpath-expression-for-string-padding-in-wso2-esb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!