繁体   English   中英

WSO2 EI 和 XSLT 介体

[英]WSO2 EI and XSLT Mediator

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

output 是这样来的:

<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

谢谢

更新的答案

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM