wso2 ESB 中是否有用于字符串填充的 XPath 表达式? [英] Is there any XPath expression for String Padding in wso2 ESB?

查看:32
本文介绍了wso2 ESB 中是否有用于字符串填充的 XPath 表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 synapse.properties 中启用了 XPath 2.0 配置 synapse.xpath.dom.failover.enabled=true 但仍然无法完成字符串填充.有什么表达方式可以实现吗?

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?

特定字符串的长度需要为 10 个字符,如果小于它,我们必须用特殊字符 '%' 填充它.

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 '%'.

例如,Input = 'WSO2',填充后应该是'WSO2%%%%%%'

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

提前致谢

推荐答案

这可以像这样使用 XPath 1.0 来实现,假设在实际实现中 "WSO2" 将被动态输入字符串替换:

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)

上述 XPath 的工作原理基本上是将 10 个特定的 for-padding 字符的字符串连接到原始输入字符串,然后将结果子串化以仅获取前 10 个字符.在以下 XSL 问题中发现了这个技巧:XSL 左右对齐与 Padding

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 : 填充操作将应用到的字符串
  • % : 用于填充的字符,重复n
  • 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
    • 这篇关于wso2 ESB 中是否有用于字符串填充的 XPath 表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆