首页 > 解决方案 > Datapower_Remove 除 SOAP 到 JSONX XSLT 中的一个以外的所有 Null 元素

问题描述

我有一个要求,我正在接收我正在转换为 JSONX 的 datapower 中的 SOAP 响应,因为响应非常大,我正在使用下面的代码删除所有空元素。但在这里我不需要删除一些元素,即使我是从支持中获取空值。任何人都可以帮忙吗?

    <xsl:apply-templates mode="removenullfields" select="$response"/>
    <xsl:template mode="removenullfields" match="node()|@*">
    <xsl:copy>
    <xsl:apply-templates mode="removenullfields" select="node()|@*"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template mode="removenullfields" match="*[not(normalize-space())]"/>
    <xsl:template mode="removenullfields" match="*[not(self::elementname)][not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>

下面是我从后端获得的示例响应 xml,我将其转换为 JSON,我想删除所有来自支持的空元素和对象。我只想发送这些元素(指控、协调员-标题,createUser-userId)即使它使用通用逻辑从后端为空,因为我的 xslt 非常大,你能帮我吗?

<soap:Envelope>
   <soap:Body>
      <Response>
      <Disp>
            <agency/>
            <allegation>Test</allegation>
            <test>
               <firstName>Test</firstName>
               <lastName>Test</lastName>
               <type>Test</type>
            </test>
            <coordinator>
               <userId></userId>
               <title>Test</title>
               <email></email>
            </coordinator>
            <Date>Test</Date>
            <User>
               <Id></Id>
               <clientName>0</clientName>
            </User>
             </Disp>
      </Response>
   </soap:Body>
</soap:Envelope>

我在json到soap转换中尝试了以下逻辑。即使我将空值传递给请求中的指控字段,它也能正常工作。同样的逻辑不适用于 SOAP 到 JSON 的转换

  <xsl:template mode="removenullfields" match="*[not(self::allegation)][not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>

标签: xsltxslt-1.0xslt-2.0ibm-datapower

解决方案


推荐阅读