Xml XSLT删除SOAP信封但保留名称空间
我需要从soap消息中删除soap信封。为此,我想使用XSLT,而不是java。对于操作这种类型的xml,它将是更合适的解决方案 例如,我有一条soap消息:Xml XSLT删除SOAP信封但保留名称空间,xml,xslt,Xml,Xslt,我需要从soap消息中删除soap信封。为此,我想使用XSLT,而不是java。对于操作这种类型的xml,它将是更合适的解决方案 例如,我有一条soap消息: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tar="namespace" xmlns:tar1="namespace">
<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>
?
?
我希望我的输出是这样的:
<tar:RegisterUser xmlns:tar="namespace" xmlns:tar1="namespace">
<tar1:Source>?</tar1:Source>
<tar1:Profile>
<tar1:EmailAddress>?</tar1:EmailAddress>
</tar1:Profile>
</tar:RegisterUser>
?
?
有人能为我提供一些关于如何做这件事的想法吗?
<?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>
输出:
<?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>
?
?
不幸的是,我找不到任何简单的方法来删除xmlns:soapenv
属性。
输出:
<?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>
?
?
不幸的是,我找不到任何简单的方法来删除
xmlns:soapenv
属性。这就去掉了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>
结果:
<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>
?
?
这将去掉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>
结果:
<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>
?
?
要删除不必要的名称空间声明,请将exclude result namespaces=“soapenv”
属性添加到
我尝试过,但Saxon、Xalan和MSXML仍然包含名称空间。哦,当然,这将是exclude result prefixes=“soapenv”
。但您是对的,名称空间保留在中是因为
。请参阅我的解决方案,了解删除信封和名称空间的更优雅的方法。要删除不必要的名称空间声明,请将排除结果名称空间=“soapenv”
属性添加到
我尝试过,但Saxon、Xalan和MSXML仍然包含名称空间。哦,这将是排除结果前缀=当然是“soapenv”
。但是你是对的,名称空间之所以保留是因为
。请参阅我的解决方案,以获得一种更优雅的方式,同时删除信封和名称空间。