1

我当前的实现请求正文不支持可选属性:

在此处输入图像描述

如果说phoneHomenull,那么想要的行为是JSON根本不包含该属性,例如我想要的是:

{ 
    "phoneWork": "value here",
    "phoneMobile": "value here",
    "email": "value here"
}

不是:

{ 
    "phoneHome": "",
    "phoneWork": "value here",
    "phoneMobile": "value here",
    "email": "value here"
}

我尝试遍历事件中的所有元素并仅返回非空值,但我无法使其正常工作。伪代码:

for $i in
(
    $input.event_input[1]/xxx_Contact_Work_PHONE__c,
    $input.event_input[1]/xxx_Contact_Home_PHONE__c,
    $input.event_input[1]/xxx_Contact_Mobile_PHONE__c,
    $input.event_input[1]/xxx_Contact_Contact_EMAIL1__c 
)
return if ($i = "null")
then do nothing
else add the attribute to a JSON

有没有办法做到这一点?

4

1 回答 1

0

下面的公式,当给定一个 XML 作为输入时,将删除所有没有数据的元素。

例子

使用以下输入

<note>
  <to>Tove</to>
  <from></from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
  <element></element>
</note>

它产生以下输出

<note>
  <to>Tove</to>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

这是我找到的解决方案:

<!--Initialize variable with the input XML-->
let $sources:=$input.XML_input
<!--Initialize variable with the distinct nodes using X-PATH-->
let $labels:=fn:distinct-values($sources/*/fn:node-name(.))
return
for $s in $sources
    return 
    <source>
    {
    for $l in $labels
        <!--Return element if value exists, nothing if no value-->
        return 
        if (fn:exists($s/*[fn:node-name()=$l]/text()))
        then ($s/*[fn:node-name()=$l])
        else ""
    }
    </source>
于 2020-06-02T08:55:15.803 回答