使用 xsl 添加 SOAP header

Add SOAP header with xsl

我有一个输入 XML 和一个 XSL,我设法对 body 进行了转换,但现在我需要添加一些 header。

<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>

我怎样才能做到这一点?我要添加的 header 在 body 之前开始并在 ?

之后结束

将该内容放入与根节点匹配的模板中,并将 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">&lt;![CDATA[</xsl:text>
          
                        <xsl:apply-templates/>
                    
                        <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
                        
                    </inputXml>
                </wss:run>
            </soapenv:Body>
        </soapenv:Envelope>  
    </xsl:template>
    
</xsl:stylesheet>