WSO2 EI和XSLT介体

时间:2020-04-27 14:18:20

标签: xslt wso2 wso2esb

我有一个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

思考

2 个答案:

答案 0 :(得分:0)

更新后的答案

如果要删除所有@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

答案 1 :(得分:0)

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

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