我有一个输入XML和XSL,我设法完成了正文的转换,但现在我需要添加一些头。
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wss="http://www.adonix.com/WSS">
<soapenv:Header/>
<soapenv:Body>
<wss:run soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<callContext xsi:type="wss:CAdxCallContext">
<codeLang xsi:type="xsd:string">ENG</codeLang>
<poolAlias xsi:type="xsd:string">satest4</poolAlias>
<poolId xsi:type="xsd:string">?</poolId>
<requestConfig xsi:type="xsd:string">?</requestConfig>
</callContext>
<publicName xsi:type="xsd:string">TEST</publicName>
<inputXml xsi:type="xsd:string"><![CDATA[
// here is the body
]]>
</inputXml>
</wss:run>
</soapenv:Body>
</soapenv:Envelope>
我怎样才能做到这一点?我想添加的标题在正文之前开始,在正文之后结束?
将该内容放入与根节点匹配的模板中,并将xsl:apply-templates
放入inputXml
元素中:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" method="xml" encoding="utf-8" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wss="http://www.adonix.com/WSS">
<soapenv:Header/>
<soapenv:Body>
<wss:run soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<callContext xsi:type="wss:CAdxCallContext">
<codeLang xsi:type="xsd:string">ENG</codeLang>
<poolAlias xsi:type="xsd:string">satest4</poolAlias>
<poolId xsi:type="xsd:string">?</poolId>
<requestConfig xsi:type="xsd:string">?</requestConfig>
</callContext>
<publicName xsi:type="xsd:string">TEST</publicName>
<inputXml xsi:type="xsd:string">
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:apply-templates/>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
</inputXml>
</wss:run>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>