2

我在 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>

有人可以帮忙吗?

4

1 回答 1

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>

于 2013-05-21T06:40:25.013 回答