XSLT Soap消息

XSLT Soap消息,xslt,soap,Xslt,Soap,我无法更改SOAP响应中标记的名称。 我看到很多关于它的帖子,但我没有找到一个合适的解决方案 我的原始XML是: <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing"> <soap:Header>

我无法更改SOAP响应中标记的名称。 我看到很多关于它的帖子,但我没有找到一个合适的解决方案

我的原始XML是:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
   <soap:Header>
      <MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:4d6b87d8-fe14-4579-ac34-fe841c184a4b</MessageID>
      <RelatesTo RelationshipType="Reply" xmlns="http://www.w3.org/2005/08/addressing">uuid:1f9b0c7e-f36c-4fa3-ac2b-2377b57b6634</RelatesTo>
      <Action xmlns="http://www.w3.org/2005/08/addressing">http://xxx</Action>
   </soap:Header>
   <soap:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <OP1 xmlns="http://xxx/">
         <OPR>
            <OPO>
               <Cod>..</Cod>
               <A1>hi my...</A1>

            </OPO>
         </OPR>
      </OP1>
   </soap:Body>
</soap:Envelope>

uuid:4d6b87d8-fe14-4579-ac34-fe841c184a4b
uuid:1f9b0c7e-f36c-4fa3-ac2b-2377b57b6634
http://xxx
..
嗨,我的。。。
我想把A1换成ANAME

我的xsl是

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">

   <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
   </xsl:template>

   <xsl:template match="A1">
        <ANAME><xsl:apply-templates /></ANAME>
   </xsl:template>      
</xsl:stylesheet>


谢谢

只需将命名空间“”的命名命名空间声明添加到样式表元素中,如下所示:

xmlns:aaa="http://xxx/"
然后您可以将
A1
元素与模板中的
aaa:A1
匹配:

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:aaa="http://xxx/">

   <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
   </xsl:template>

   <xsl:template match="aaa:A1">
     <xsl:element name="ANAME" namespace="http://xxx/">
       <xsl:apply-templates />
     </xsl:element>
   </xsl:template>     

</xsl:stylesheet>

部分输出:

...
<soap:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <OP1 xmlns="http://xxx/">
        <OPR>
            <OPO>
                <Cod>..</Cod>
                <ANAME>hi my...</ANAME>

            </OPO>
        </OPR>
    </OP1>
</soap:Body>
。。。
..
嗨,我的。。。

在XML中,
OP1
元素及其所有子元素都在
xmlns=”中http://xxx/“
名称空间。请参见此处的处理方法:--还要注意,如果希望
ANAME
位于同一名称空间中,则必须将其放在该名称空间中。否则您将在输出中看到
嗨,我的…
。非常感谢!!最后一个问题,在转换中,新标记ANAME add atributte xmlns=“”,我如何处理转换?不要添加它?@AndresPastorini:我刚刚用您的输入XML重新测试了XSLT,结果如我的回答所示。在构造我的答案时,我特别考虑删除输出中的这些空
xslns=“
属性。这是通过将
ANAME
namespace=“…”
属性设置为与周围名称空间相同的值来实现的(在本例中为
)。这一点在我的回答中得到了体现。非常感谢你的帮助@安德烈斯帕斯托里尼:谢谢你的赞赏。我很高兴读到这一点。但如果我的回答有帮助的话,一个被认可的方式就是接受我的回答。