我正在尝试建立一个肥皂请求。所需的输出是:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:soap1="http://acme.com/ws/soapheaders">
<soap:Header>
<soap1:locale>en</soap1:locale>
<soap1:authentication>
<soap1:username>john.doe</soap1:username>
<soap1:password>psw</soap1:password>
</soap1:authentication>
</soap:Header>
这是我的测试 xsl(语言、用户名和密码将在实际应用程序中传递):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="language" select="'en'"/>
<xsl:param name="username" select="'john.doe'"/>
<xsl:param name="password" select="'psw'"/>
<xsl:template match="/">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:soap1="http://acme.com/ws/soapheaders" >
<xsl:call-template name="soapHeader"/>
<xsl:call-template name="soapBody"/>
</soap:Envelope>
</xsl:template>
<xsl:template name="soapHeader">
<soap:Header>
<soap1:locale><xsl:value-of select="$language" /></soap1:locale>
<soap1:authentication>
<soap1:username><xsl:value-of select="$username" /></soap1:username>
<soap1:password><xsl:value-of select="$password" /></soap1:password>
</soap1:authentication>
</soap:Header>
</xsl:template>
<xsl:template name="soapBody">
</xsl:template>
</xsl:stylesheet>
但是,输出是:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soap1="http://acme.com/ws/soapheaders">
<soap:Header xmlns:soap="">
<soap1:locale xmlns:soap1="">en</soap1:locale>
<soap1:authentication xmlns:soap1="">
<soap1:username>john.doe</soap1:username>
<soap1:password>psw</soap1:password>
</soap1:authentication>
</soap:Header>
有不需要的空命名空间,例如 xmlns:soap=""、xmlns:soap1=""。你能给我指出正确的方向来消除这些不需要的伪影吗?
谢谢。