如果要在XSLT中使用名稱空間,則必須聲明它們。讓我們假設你的來源是這樣的:
<months>
<month>January</month>
<month>August</month>
</months>
既然你需要在你的屬性前綴,你必須聲明的命名空間。您沒有顯示名稱空間,所以我將使用隨機字符串。下面的XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:boolean="put-your-namespace-here">
<xsl:template match="months">
<seasons><xsl:apply-templates/></seasons>
</xsl:template>
<xsl:template match="month">
<season>
<xsl:if test="text() = 'August'">
<xsl:attribute name="boolean:warm">true</xsl:attribute>
</xsl:if>
<xsl:value-of select="."/>
</season>
</xsl:template>
</xsl:stylesheet>
將產生以下結果:
<seasons xmlns:boolean="put-your-namespace-here">
<season>January</season>
<season boolean:warm="true">August</season>
</seasons>
是與命名空間問題,也許?您的條件屬性不是使用名稱空間創建的。也許你可以顯示「布爾」前綴的名稱空間?謝謝! –