2011-04-14 128 views
1

我正在做一些xforms開發並且有一個匹配選擇項目的模板。如果它是一個單一的選擇,而不是多,我想一個空值添加到給定列表的頂部:我如何測試xsl中的名稱空間元素名稱

<xsl:template match="xforms:select1|xforms:select"> 
    <xsl:apply-templates select="node()" /> 
    <xsl:if test=".[name()='xf:select1'] and not (@appearance eq 'full')"> 
     <xforms:item> 
      <xforms:label /> 
      <xforms:value /> 
     </xforms:item> 
    </xsl:if> 
    ... 

的問題是,這個工作對我的表格上有一座xf:select1(因爲match一個是名稱空間感知),但由於name()測試僅適用於字符串,因此另一種形式的xforms:select1控件已損壞。

有沒有一種方法可以使此語句工作,無論我爲http://www.w3.org/2002/xforms命名空間創建什麼前綴?

回答

1

你一定要避免依賴於命名空間的任何代碼前綴。我想你想使用自我軸:

<xsl:if test="self::xforms:select1 and not (@appearance eq 'full')"> 
0

我所做的是將if分割成不同的模板......我喜歡它,因爲它是xsl的目標;我恨它,因爲它的一些匹配邏輯,將在多個地方被改變,如果它有一個bug或改進的另一個副本...

<xsl:template match="xforms:select1[not(xforms:itemset) and not(@appearance eq 'full')]" priority="10"> 
    <xsl:apply-templates select="node()" /> 
    <xforms:item> 
     <xforms:label /> 
     <xforms:value /> 
    </xforms:item> 
    <xsl:call-template name="select-itemset"/> 
</xsl:template> 

<xsl:template match="xforms:select1[not(xforms:itemset)]|xforms:select[not(xforms:itemset)]"> 
    <xsl:apply-templates select="node()" /> 
    <xsl:call-template name="select-itemset"/> 
</xsl:template> 

<xsl:template name="select-itemset"> 
    ... 
相關問題