我試圖構建一個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