我正在尝试找到可以执行以下操作的XSLT。
我正在尝试将XML消息包装在快速soap信封(xml)中。源XML并不是一成不变的,因此XSLT不应该关心XML是什么。它确实需要将XML声明从XML的顶部剥离。
示例:
<?xml version="1.0"?>
<foo>
<bar />
</foo>
转换为:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:hl7-org:v3">
<soapenv:Header/>
<soapenv:Body>
<foo>
<bar />
</foo>
</soapenv:Body>
</soapenv:Envelope>
示例2:
<lady>
<and>
<the>
<tramp />
</the>
</and>
</lady>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:hl7-org:v3">
<soapenv:Header/>
<soapenv:Body>
<lady>
<and>
<the>
<tramp />
</the>
</and>
</lady>
</soapenv:Body>
</soapenv:Envelope>
答案 0 :(得分:2)
这个XSLT:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="*">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:hl7-org:v3">
<soapenv:Header/>
<soapenv:Body>
<xsl:copy-of select="/*"/>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>
输出此XML:
<soapenv:Envelope xmlns="urn:hl7-org:v3" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<lady xmlns="">
<and>
<the>
<tramp/>
</the>
</and>
</lady>
</soapenv:Body>
</soapenv:Envelope>
答案 1 :(得分:2)
您可以使用此功能(类似于Phoenixblade9&#39的答案,但不使用xsl:element
)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:hl7-org:v3">
<soapenv:Header/>
<soapenv:Body>
<xsl:copy-of select="*"/>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>