Xslt:动态创建根元素(起始标记)



以下是XML数据中的节点

 <WebServiceUrl>"http://webser.part.site"</WebServiceUrl>
<UserName>nida</UserName>
<Passsword>123</Password>
</ProcessData>

我已经将这个节点值传递给Xslt服务,现在我在参数e-g 中有这个url节点值

<xsl:param name="UserName"/>
<xsl:param name="Password"/>
<xsl:param name="WebServiceUrl"/>

现在我想创建一个soapenv:Envelope标记,并在其中使用这个值

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="$WebServiceUrl">

因此,我想要从XSLT代码中得到的最终输出是:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"          xmlns:web="http://webservice2.partner.insite">
 <soapenv:Header/>
<soapenv:Body>
<web:upload>
<web:username>nida</web:username>
<web:password>123</web:password>
</web:upload></soapenv:Body></soapenv:Envelope>

请帮我

此转换

<xsl:stylesheet version="1.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:ext="http://exslt.org/common"
     xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
     exclude-result-prefixes="ext soapenv">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
      <xsl:param name="pUserName" select="'nida'"/>
      <xsl:param name="pPassword" select="'123'"/>
      <xsl:param name="pWebServiceUrl" select="'http://webser.part.site'"/>
        <xsl:variable name="vrtfDummy">
         <xsl:element name="web:dummy" namespace="{$pWebServiceUrl}"/>
        </xsl:variable>
        <xsl:variable name="vNS" select="ext:node-set($vrtfDummy)/*/namespace::web"/>
     <xsl:template match="/*">
       <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
           <xsl:copy-of select="$vNS"/>
         <soapenv:Body>
           <xsl:element name="web:upload" namespace="{$vNS}">
             <xsl:element name="web:username" namespace="{$vNS}">
               <xsl:value-of select="$pUserName"/>
             </xsl:element>
             <xsl:element name="web:password" namespace="{$vNS}">
               <xsl:value-of select="$pPassword"/>
             </xsl:element>
           </xsl:element>
         </soapenv:Body>
         </soapenv:Envelope>
     </xsl:template>
</xsl:stylesheet>

应用于任何XML文档(未使用)时,会产生所需的正确结果:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webser.part.site">
   <soapenv:Body>
      <web:upload>
         <web:username>nida</web:username>
         <web:password>123</web:password>
      </web:upload>
   </soapenv:Body>
</soapenv:Envelope>

最新更新