XSLT删除SOAP信封但保留名称空间

Pau*_*nis 1 xml xslt

我需要从肥皂信息中删除肥皂信封.为此,我想使用XSLT,而不是java.对于操作这种类型的xml来说,这将是更合适的解决方案.

例如,我有一个肥皂消息:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                  xmlns:tar="namespace" 
                  xmlns:tar1="namespace">
    <soapenv:Header/>
    <soapenv:Body>
        <tar:RegisterUser>
            <tar1:Source>?</tar1:Source>
            <tar1:Profile>
                <tar1:EmailAddress>?</tar1:EmailAddress>

            </tar1:Profile>
        </tar:RegisterUser>
    </soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

我希望我的输出是这样的:

<tar:RegisterUser xmlns:tar="namespace" xmlns:tar1="namespace">
    <tar1:Source>?</tar1:Source>
    <tar1:Profile>
        <tar1:EmailAddress>?</tar1:EmailAddress>

    </tar1:Profile>
</tar:RegisterUser>
Run Code Online (Sandbox Code Playgroud)

有人可以提供一些关于如何做到这一点的想法吗?

Tom*_*lak 8

这摆脱了soapenv:元素命名空间声明.

<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>
Run Code Online (Sandbox Code Playgroud)

结果:

<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>
Run Code Online (Sandbox Code Playgroud)