简体   繁体   English

WSO2 EI 和 XSLT 介体

[英]WSO2 EI and XSLT Mediator

I have a SOAP call returning the following:我有一个 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>

I need to treat the return through a XSLT Mediator in WSO2 Enterprise Integrator 6.6.0.我需要通过 WSO2 Enterprise Integrator 6.6.0 中的 XSLT 调解器处理退货。

Some of the attributes return with the content:一些属性随内容返回:

xsi:nil="true"

I need the my mediator to replace these tags with empty values for my attributes.我需要我的中介用我的属性的空值替换这些标签。

My current Mediator is with following:我目前的调解员如下:

<?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>

The output is coming like this: 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>

As example:例如:

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

I need it to become:我需要它变成:

<ax2696:successKey></ax2696:successKey>

I need to do this for most of the attributes not only successKey我需要对大多数属性执行此操作,而不仅仅是 successKey

Thks谢谢

Updated answer更新的答案

If you want to remove all @xsi:nil='true'如果要删除所有 @xsi:nil='true'

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

If you want to remove @xsl:nil='true' only on certain nodes如果您只想在某些节点上删除 @xsl:nil='true'

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

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

Original answer原始答案

Not sure I really understand your question.不确定我是否真的理解你的问题。 Is this what you are trying to achieve?这是你想要达到的目标吗?

Replace代替

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

By经过

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

See it working here: https://xsltfiddle.liberty-development.net/pNmC4J4看到它在这里工作: https://xsltfiddle.liberty-development.net/pNmC4J4

Your template matches any element that has a xsi:nil="true" attribute and removes it.您的模板匹配任何具有xsi:nil="true"属性的元素并将其删除。 If you want to remove only the attribute itself, make it:如果您只想删除属性本身,请使其:

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

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

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