XSLT to remove SOAP envelope but leave namespaces

前端 未结 2 1501
天命终不由人
天命终不由人 2021-01-16 10:54

I need to remove soap envelope from soap message. For that I want to use XSLT, not java. It would be more proper solution for operating such type of xml.

For e.g. I

相关标签:
2条回答
  • 2021-01-16 11:04

    This gets rid of the soapenv: elements and the namespace declaration.

    <xsl:stylesheet 
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    >
      <xsl:output indent="yes" />
    
      <xsl:template match="@* | node()">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="soapenv:*">
        <xsl:apply-templates select="@* | node()" />
      </xsl:template>
    </xsl:stylesheet>
    

    Result:

    <tar:RegisterUser xmlns:tar="namespace">
      <tar1:Source xmlns:tar1="namespace">?</tar1:Source>
      <tar1:Profile xmlns:tar1="namespace">
        <tar1:EmailAddress>?</tar1:EmailAddress>
      </tar1:Profile>
    </tar:RegisterUser>
    
    0 讨论(0)
  • 2021-01-16 11:13
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        version="1.0">
    
        <xsl:output method="xml" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="/">
            <xsl:copy-of select="/soapenv:Envelope/soapenv:Body/*"/>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <?xml version="1.0" encoding="utf-8"?>
    <tar:RegisterUser xmlns:tar="namespace" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tar1="namespace">
        <tar1:Source>?</tar1:Source>
        <tar1:Profile>
            <tar1:EmailAddress>?</tar1:EmailAddress>
        </tar1:Profile>
    </tar:RegisterUser>
    

    Unfortunately, I could not find any easy way to remove the xmlns:soapenv attribute.

    0 讨论(0)
提交回复
热议问题