我有一个xml,我想重命名/更改元素名称并保持不变,但我面临意外的结果。
传入XML
<?xml version="1.0" encoding="utf-8"?>
<PublishVENDOR baseLanguage="EN" messageID="507085.1468382418796837538" event="1" xmlns="http://store/companies" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<VENDORSet>
<COMPANIES action="Replace">
<ADDRESS1>32 SUMNER STREET</ADDRESS1>
<ADDRESS2>HARTFORD</ADDRESS2>
<ADDRESS3>CT</ADDRESS3>
<ADDRESS4>03342</ADDRESS4>
</COMPANIES>
</VENDORSet>
</PublishVENDOR>
&#13;
XSL地图
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="http://store/companies" version="1.0">
<xsl:template match="/ns:PublishVENDOR">
<xsl:element name="SyncVENDOR">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
&#13;
结果
<?xml version="1.0" encoding="utf-8"?>
<SyncMXVENDOR baseLanguage="EN" messageID="507085.1468382418796837538" event="1">
<VENDORSet xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<COMPANIES action="Replace">
<ADDRESS1>32 SUMNER STREET</ADDRESS1>
<ADDRESS2>HARTFORD</ADDRESS2>
<ADDRESS3>CT</ADDRESS3>
<ADDRESS4>03342</ADDRESS4>
</COMPANIES>
</VENDORSet>
</SyncVENDOR>
&#13;
我想要的结果是
<?xml version="1.0" encoding="utf-8"?>
<SyncVENDOR baseLanguage="EN" messageID="507085.1468382418796837538" event="1" xmlns="http://store/companies" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<VENDORSet>
<COMPANIES action="Replace">
<ADDRESS1>32 SUMNER STREET</ADDRESS1>
<ADDRESS2>HARTFORD</ADDRESS2>
<ADDRESS3>CT</ADDRESS3>
<ADDRESS4>03342</ADDRESS4>
</COMPANIES>
</VENDORSet>
</SyncVENDOR>
&#13;
请有人帮助我...我很抱歉我的英语也不好
答案 0 :(得分:0)
更改
<xsl:template match="/ns:PublishVENDOR">
<xsl:element name="SyncVENDOR">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
到
<xsl:template match="/ns:PublishVENDOR">
<SyncVENDOR xmlns="http://store/companies">
<xsl:copy-of select="namespace::*"/>
<xsl:apply-templates select="@*|node()"/>
</SyncVENDOR>
</xsl:template>