我试图改变元素的命名空间属性使用下面的XSL代码:XSLT改变命名空间在元素
<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:ns2="http://www.ean-ucc.org/schemas/1.3.1/eanucc">
<xsl:output encoding='UTF-8' indent='yes' method='xml'/>
<!-- copy everything into the output -->
<xsl:template match='@*|node()'>
<xsl:copy>
<xsl:apply-templates select='@*|node()'/>
</xsl:copy>
</xsl:template>
<xsl:template match="IRenvelope">
<IRL xmlns:xsd="http://www.xx.com">
<xsl:copy-of select="node()|@*"/>
</IRL>
</xsl:template>
</xsl:stylesheet>
我使用用于测试的XML消息是:
<GMessage xmlns="http://www.giffgaff.uk/CM/envelope">
<EnvelopeVersion>2.0</EnvelopeVersion>
<body>
<IRenvelope xmlns="http://www.mnv.com/elc/sap">
<Keys>
<Key Type="TaxOfficeNumber">635</Key>
</Keys>
</IRenvelope>
</body>
</GMessage>
我不能让它工作,命名空间不变,但收益相同的结果。请帮忙吗?
输出的XML如下:
<GMessage xmlns="http://www.giffgaff.uk/CM/envelope">
<EnvelopeVersion>2.0</EnvelopeVersion>
<body>
<IRenvelope xmlns="http://www.xx.com">
<Keys>
<Key Type="TaxOfficeNumber">635</Key>
</Keys>
</IRenvelope>
</body>
</GMessage>
在输入XML元素,'IRenvelope',落在命名空间'HTT下号码:// www.mnv.com/ELC/sap'。但是你的XSLT匹配没有这个名字空间的元素'IRenvelope'。此外,您创建的元素“IRL”属于空名称空间。如果您希望它位于'http:// www.xx.com'下,则元素名称应该带有'xsd'前缀('xsd:IRL')。 –
thkx您的反馈。我为IRInvelope处于名称范围之内做了些什么,并将附带的输出提供给我?请输入任何内容? –