简体   繁体   中英

WSO2 EI and XSLT Mediator

I have a SOAP call returning the following:

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

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:

<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

Thks

Updated answer

If you want to remove all @xsi:nil='true'

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

If you want to remove @xsl:nil='true' only on certain nodes

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

See an example here: 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

Your template matches any element that has a xsi:nil="true" attribute and removes it. If you want to remove only the attribute itself, make it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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