【发布时间】:2019-09-16 13:12:48
【问题描述】:
我有一个 xml 作为源,并希望进行以下更改。 1.删除第一个根标签 2.添加新的soapenv根标签 3. 从源中删除命名空间。
我可以添加新标签,但是 XSLT1.0 版本没有完成删除。(我已经用 XSLT2.0 实现了它,但我的 XSLT 处理器是 1.0)。我知道我在这里遗漏了一些基本逻辑。有人可以帮帮我吗。非常感谢。
源 XML:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Header xmlns:ns0="http://xyz987.com">
<Main>
<Parent2>
<status>12</status>
<status_txt>Helo</status_text>
</Parent2>
<Parent3>
<Child1>112</Child1>
<Child2>Hai</Child2>
</Parent3>
<Parent4>
<Child3>Valley</Child3>
<Parent5>
<Child7>Kind</Child7>
<Child8>Pls</Child8>
</Parent5>
</Parent4>
</Main>
</ns0:Header>
目标 XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<Main>
<Parent2>
<status>12</status>
<status_txt>Helo</status_txt>
</Parent2>
<Parent3>
<Child1>112</Child1>
<Child2>Hai</Child2>
</Parent3>
<Parent4>
<Child3>Valley</Child3>
<Parent5>
<Child7>Kind</Child7>
<Child8>Pls</Child8>
</Parent5>
</Parent4>
</Main>
</soapenv:Body>
</soapenv:Envelope>
XSLT 试过了:
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
<xsl:template match="*">
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<soapenv:Header/>
<soapenv:Body>
<xsl:copy-of select="*" copy-namespaces="no"/>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>
【问题讨论】: