我试图构建一个Soap请求。所需的输出是:如何从xslt输出xml中删除不需要的空xmlns
<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(lanuage,用户名和密码在实际应用中传递):
<?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 =“”。你能指点我正确的方向来消除这些不需要的文物吗?
谢谢。
User2254613,我强烈建议使用一种设计模式,使演示文稿与逻辑完全分离 - 又名“填充空白”技术。 – 2013-04-07 16:09:58