Xslt :动态创建根元素(起始标签) [英] Xslt : Create root element (Starting Tag )dynamically

查看:23
本文介绍了Xslt :动态创建根元素(起始标签)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是 XML Data 中的节点

Following are the nodes in XML Data

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

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

I have passed this node value to Xslt Service now i have this url NODE value in parameter e-g

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

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

Now i want to create a soapenv:Envelope tag and use this value in it

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

所以我想从 XSLT 代码中得到的最终输出如下:

So the final outPut which i want from XSLT Code is as :

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

这篇关于Xslt :动态创建根元素(起始标签)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆