2013-05-21 23 views
2

我有選擇使用buttons.I需要檢查值和設定活躍的兩個值在XSLT代碼對應的button.here是我的代碼如何在xslt中設置活動按鈕?

<ul class="switch"> 
<li class="private-btn"> 
<xsl:if test="library:RequestQueryString('at') = 'privat'"> 

here i need the active btn code 

</xsl:if> 
<input type="button" class="Privat" value="Privat"></input> 

</li> 
<li class="business-btn"> 
<xsl:if test="library:RequestQueryString('at') = 'Erhverv'"> 

    here i need the active btn code 

</xsl:if> 
<input type="button" class="Privat" value="Erhverv"></input> 
</li> 
</ul> 

任何人可以幫助?

回答

2

如果我正確理解你,你想有條件地設置按鈕上的disabled html屬性(以及其他屬性)。

可以有條件地添加屬性,像這樣:

<input type="button" class="Privat" value="Erhverv"> 
    <xsl:choose> 
    <xsl:when test="library:RequestQueryString('at') = 'privat'"> 
     <xsl:attribute name="disabled">disabled</xsl:attribute> 
    </xsl:when> 
    <xsl:otherwise> 
     ... Other attribute here etc. 
    </xsl:otherwise> 
    </xsl:choose> 
</input> 

因爲它似乎需要重用的邏輯,你也可以重構啓用/屬性狀態代入呼叫模板,就像這樣:

<xsl:template name="SetActiveState"> 
    <xsl:param name="state"></xsl:param> 
    <xsl:choose> 
     <xsl:when test="$state='true'"> 
     <xsl:attribute name="disabled">disabled</xsl:attribute> 
     </xsl:when> 
     <xsl:otherwise>...</xsl:otherwise> 
    </xsl:choose> 
    </xsl:template> 

然後調用它像這樣:

<input type="button" class="Privat" value="Erhverv"> 
    <xsl:call-template name="SetActiveState"> 
    <xsl:with-param name="state" 
        select="library:RequestQueryString('at') = 'privat'"> 
    </xsl:with-param> 
    </xsl:call-template> 
</input> 

...同樣爲<input type="button" class="Privat" value="Privat"></input>

相關問題