【问题标题】:WSO2 EI and XSLT MediatorWSO2 EI 和 XSLT 中介
【发布时间】:2020-05-02 01:44:11
【问题描述】:

我有一个 SOAP 调用返回以下内容:

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
   <soapenv:Body>
      <ns:getTenantResponse xmlns:ns="http://services.mgt.tenant.carbon.wso2.org">
         <ns:return xsi:type="ax2696:TenantInfoBean" xmlns:ax2696="http://beans.common.stratos.carbon.wso2.org/xsd" xmlns:ax2698="http://exception.common.stratos.carbon.wso2.org/xsd" xmlns:ax2700="http://api.user.carbon.wso2.org/xsd" xmlns:ax2702="http://beans.mgt.tenant.carbon.wso2.org/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ax2696:active>true</ax2696:active>
            <ax2696:admin>admin</ax2696:admin>
            <ax2696:adminPassword xsi:nil="true"/>
            <ax2696:createdDate>2020-03-31T18:05:30.321-03:00</ax2696:createdDate>
            <ax2696:email>erico@mail.com</ax2696:email>
            <ax2696:firstname>erico</ax2696:firstname>
            <ax2696:lastname>mtx</ax2696:lastname>
            <ax2696:originatedService xsi:nil="true"/>
            <ax2696:successKey xsi:nil="true"/>
            <ax2696:tenantDomain>dom20.com</ax2696:tenantDomain>
            <ax2696:tenantId>1</ax2696:tenantId>
            <ax2696:usagePlan/>
         </ns:return>
      </ns:getTenantResponse>
   </soapenv:Body>
</soapenv:Envelope>

我需要通过 WSO2 Enterprise Integrator 6.6.0 中的 XSLT 中介处理退货。

一些属性随内容返回:

xsi:nil="true"

我需要我的中介将这些标签替换为我的属性的空值。

我目前的调解员是以下人员:

<?xml version="1.0"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  version="1.0">
  <xsl:output omit-xml-declaration="no" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="*[@xsi:nil = 'true']" />
</xsl:stylesheet>

输出如下:

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
   <soapenv:Body>
      <ns:getTenantResponse xmlns:ns="http://services.mgt.tenant.carbon.wso2.org">
         <ns:return xsi:type="ax2696:TenantInfoBean" xmlns:ax2696="http://beans.common.stratos.carbon.wso2.org/xsd" xmlns:ax2698="http://exception.common.stratos.carbon.wso2.org/xsd" xmlns:ax2700="http://api.user.carbon.wso2.org/xsd" xmlns:ax2702="http://beans.mgt.tenant.carbon.wso2.org/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ax2696:active>true</ax2696:active>
            <ax2696:admin>admin</ax2696:admin>
            <ax2696:adminPassword xsi:nil="true"/>
            <ax2696:createdDate>2020-03-31T18:05:30.321-03:00</ax2696:createdDate>
            <ax2696:email>erico@skalena.com</ax2696:email>
            <ax2696:firstname>erico</ax2696:firstname>
            <ax2696:lastname>teixeira</ax2696:lastname>
            <ax2696:originatedService xsi:nil="true"/>
            <ax2696:successKey xsi:nil="true"/>
            <ax2696:tenantDomain>dom20.com</ax2696:tenantDomain>
            <ax2696:tenantId>1</ax2696:tenantId>
            <ax2696:usagePlan/>
         </ns:return>
      </ns:getTenantResponse>
   </soapenv:Body>
</soapenv:Envelope>

例如:

<ax2696:successKey xsi:nil="true"/>

我需要它变成:

<ax2696:successKey></ax2696:successKey>

我需要对大多数属性执行此操作,而不仅仅是 successKey

感谢

【问题讨论】:

  • 你能发布预期的输出吗?
  • 你好 Sebastien,我已经用当前输出和我需要的内容更新了内容。谢谢!!
  • 我不明白您怎么说您的转换需要 XML 输入并将其转换为某种 JSON?当我对您的输入运行转换时,我得到了预期的 XML 输出。
  • 您的问题没有得到解答吗?如果没有,为什么不呢?

标签: xslt wso2 wso2esb


【解决方案1】:

您的模板匹配任何具有xsi:nil="true" 属性的元素并将其删除。如果您只想删除属性本身,请制作:

<xsl:template match="@xsi:nil[. = 'true']" />

【讨论】:

    【解决方案2】:

    更新答案

    如果要删除所有@xsi:nil='true'

    <xsl:template match="@xsi:nil"/>
    

    如果您只想在某些节点上删除 @xsl:nil='true'

    <xsl:template match="@xsi:nil[local-name(parent::*) = 'originatedService']"/>
    

    在此处查看示例:https://xsltfiddle.liberty-development.net/pNmC4J4/1

    原答案

    不确定我是否真的理解你的问题。这是你想要达到的目标吗?

    替换

      <!-- TEMPLATE #2 -->
      <xsl:template match="*[@xsi:nil = 'true']" />
    

      <!-- TEMPLATE #2 -->
      <xsl:template match="@xsi:nil[. = 'true']">
          <xsl:attribute name="nil" namespace="http://www.w3.org/2001/XMLSchema-instance"/>
      </xsl:template>
    

    在这里看到它的工作:https://xsltfiddle.liberty-development.net/pNmC4J4

    【讨论】:

    • 我需要替换,例如在我的来源中: 。但是有些记录 originServices 不为空……在这些情况下,我需要显示值
    • 更新您的原始问题以显示完整示例。如果我看不到您正在处理的内容,我真的无能为力。
    • 抱歉给我带来了麻烦。我已经编辑了内容,好吗?谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多