繁体   English   中英

选择一个默认值 <select> XSL文件中的语句

[英]Selecting a default value in a <select> statement in a XSL file

我有一个项目列表,例如下面的列表,我试图默认选择该选项,该选项在“ listing”标签内具有特定标签。

<select>
<xsl:attribute name="name"><xsl:value-of select="@id"/>_type</xsl:attribute>
<option><xsl:attribute name="value"><xsl:if test="listing/Chat"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>Chat</xsl:attribute>Chat</option>
...

我是否将xsl:if放置不正确?

您的代码无效,因为您已将一个<xsl:attribute>标记嵌套在另一个标记中。 我相信您想要以下内容之一:

<select name="{@id}_type">
    <option value="Chat">
        <xsl:if test="listing/Chat">
            <xsl:attribute name="selected">selected</xsl:attribute>
        </xsl:if>

        <xsl:text>Chat</xsl:text>
    </option>
</select>

要么

<select name="{@id}_type">
    <xsl:if test="listing/Chat">
        <option value="Chat" selected="selected">Chat</option>
    </xsl:if>
</select>

前者始终显示“聊天”选项,但只有在满足条件时才选择它。 除非满足条件,否则后者根本不会显示“聊天”。

从您提供的代码中很难看出来,但是我猜您想要的结果看起来像这样:

<select name="000_type">
<option value="chat" selected="selected"/>
<option value="chat"/>
</select>

在这种情况下,您需要如下所示的XSL:

<xsl:element name="select">
    <xsl:attribute name="name" select="concat(@id,'_type'))"/>
</xsl:element>
<xsl:element name="option">
    <xsl:attribute name="value">
       <xsl:value-of select="chat"/>
    </xsl:attribute>
    <xsl:if test="listing/Chat">
       <xsl:attribute name="selected">
          <xsl:text>selected</xsl:text>
       </xsl:attribute>
    </xsl:if>
</xsl:element>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM