1
<LineProcessInfo>
  <LineRefTextField1>JPY</LineRefTextField1>
  <LineRefTextField2>[MW09449_ _048]</LineRefTextField2>
  <LineRefTextField3>[00_L]</LineRefTextField3>
  <LineRefTextField4></LineRefTextField4>
  <LineRefTextField5>AS LAMBSWOOL VNECK</LineRefTextField5>
  <LineRefTextField6>Jet Black Heath</LineRefTextField6>
  <LineRefTextField7></LineRefTextField7>
  <LineRefTextField8>WH01</LineRefTextField8>
  <LineRefTextField9></LineRefTextField9>
  <LineRefTextField10></LineRefTextField10>
  <LineRefNumberField1></LineRefNumberField1>
  <LineRefNumberField2></LineRefNumberField2>
  <LineRefNumberField3>22</LineRefNumberField3>
  <LineRefNumberField4></LineRefNumberField4>
  <LineRefNumberField5></LineRefNumberField5>
</LineProcessInfo> 

值:如果(LineItem.LineProcessInfo.LineRefNumberField3 != null)(LineItem.LineProcessInfo.LineRefNumberField3)否则“”

对于 LineRefNumberField3 长度应为 5,如果小于 5,则向左填充零,我需要得到 00022,请建议如何实现。

4

1 回答 1

1

您可以按照https://docs.mulesoft.com/mule-runtime/4.2/dw-strings-functions-leftpad中的说明使用 leftPad

下面的示例代码:

%dw 2.0
output application/json

import * from dw::core::Strings

var payload = read("<LineProcessInfo><LineRefTextField1>JPY</LineRefTextField1>
          <LineRefTextField2>[MW09449_ _048]</LineRefTextField2>
          <LineRefTextField3>[00_L]</LineRefTextField3>
          <LineRefTextField4></LineRefTextField4>
          <LineRefTextField5>AS LAMBSWOOL VNECK</LineRefTextField5>
          <LineRefTextField6>Jet Black Heath</LineRefTextField6>
          <LineRefTextField7></LineRefTextField7>
          <LineRefTextField8>WH01</LineRefTextField8>
          <LineRefTextField9></LineRefTextField9>
          <LineRefTextField10></LineRefTextField10>
          <LineRefNumberField1></LineRefNumberField1>
          <LineRefNumberField2></LineRefNumberField2>
          <LineRefNumberField3>22</LineRefNumberField3>
          <LineRefNumberField4></LineRefNumberField4>
          <LineRefNumberField5></LineRefNumberField5>
        </LineProcessInfo>", "application/xml")
---

{
    LineRefNumberField3: leftPad(payload.LineProcessInfo.LineRefNumberField3, 5, "0") default ""
}

编辑: 如果使用 Mule Runtime v4.1.x

(payload.LineProcessInfo.LineRefNumberField3 as Number default "") as String {format : "00000"}
于 2020-01-09T17:19:26.430 回答