Xml Xslt:动态创建根元素(起始标记)
以下是XML数据中的节点Xml Xslt:动态创建根元素(起始标记),xml,xml-parsing,xslt-1.0,xmlspy,Xml,Xml Parsing,Xslt 1.0,Xmlspy,以下是XML数据中的节点 ”http://webser.part.site" 奈达 123 我已经将这个节点值传递给Xslt服务,现在在参数e-g中有了这个url节点值 <xsl:param name="UserName"/> <xsl:param name="Password"/> <xsl:param name="WebServiceUrl"/> 现在我想创建一个soapenv:Envelope标记并在其中使用这个值 <soapenv:En
”http://webser.part.site"
奈达
123
我已经将这个节点值传递给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>
奈达
123
请帮我解决这个问题这个转变:
<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>
奈达
123
请注意,我在下面描述的指定节点中遇到了错误。当我将此XSLT应用于给定的XML时,我得到了以下不正确的输出。nida 123请查看上面的代码,它没有给出所需的输出。@NidaSulheri:那么,输出中有什么不符合预期?
<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>