我需要一个简单的xslt,它接受输入,并提供输出,如下所述。我写了一个xslt,但命名空间被忽略。请帮助我。带名称空间的XSLT转换
输入消息:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:esbMessage xmlns:ns2="http://messagev2.esb.company.com/">
<header>
<identity/>
<message-id>56b3b200-1945-44a9-9dcf-a90de1f99060</message-id>
<correlation-id>56b3b200-1945-44a9-9dcf-a90de1f99060</correlation-id>
<message-date-time>2016-11-14T11:31:49</message-date-time>
<esb-environment>DEV</esb-environment>
</header>
<errors/>
<body>
<urn:submitOrder xmlns:urn="urn:switchyard-quickstart:bean-service:1.0">
<order>
<orderId>100001</orderId>
<itemId>5001</itemId>
<quantity>5</quantity>
</order>
</urn:submitOrder>
</body>
</ns2:esbMessage>
期望输出消息:
<urn:submitOrder xmlns:urn="urn:switchyard-quickstart:bean-service:1.0">
<order>
<orderId>100001</orderId>
<itemId>5001</itemId>
<quantity>5</quantity>
</order>
</urn:submitOrder>
实际输出消息:
<submitOrder>
<order>
<orderId>100001</orderId>
<itemId>5001</itemId>
<quantity>5</quantity>
</order>
</submitOrder>
XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" encoding="utf-8"
omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:for-each select="//body">
<xsl:apply-templates select="@* | node()" />
</xsl:for-each>
</xsl:template>
<!-- template to copy elements -->
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
<!-- template to copy attributes -->
<xsl:template match="@*">
<xsl:attribute name="{local-name()}" >
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
<!-- template to copy the rest of the nodes -->
<xsl:template match="comment() | text() | processing-instruction()">
<xsl:copy />
</xsl:template>
</xsl:stylesheet>
您好,我需要删除命名空间http:// messagev2。 esb.company。com /,并且只有命名空间xmlns:urn =“urn:switchyard-quickstart:bean-service:1.0”。 – Ravi
@ user2761267请参阅编辑1的答案。 – uL1
“*我不知道为什么上面的xslt复制未使用的命名空间来输出xml。*”因为'xsl:copy'复制范围内的所有命名空间节点。 –