can';t将选定的html选择选项添加到我的xsl中

can';t将选定的html选择选项添加到我的xsl中,html,xml,xslt,if-statement,xslt-1.0,Html,Xml,Xslt,If Statement,Xslt 1.0,请仅xsl:stylesheet version=“1.0” 谢谢。您需要使用来实现该场景 <select> <xsl:for-each select="//country/state"> <option value="{id}" <xsl:choose> <xsl:when test="2 &gt; 1"><!--my true-condition,

仅xsl:stylesheet version=“1.0”

谢谢。

您需要使用
来实现该场景

<select>
    <xsl:for-each select="//country/state">
        <option value="{id}"
            <xsl:choose>
              <xsl:when test="2 &gt; 1"><!--my true-condition, will be valid for one option only-->
                selected
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>
        >
        <xsl:value-of select="city" />
        </option>
    </xsl:for-each>
</select>

挑选出来的

您可以使用xsl:attribute在XSLT1.0中动态创建属性。 在HTML中您可以编写
,但在XML或XHTML中这相当于
。在XSLT中,您需要生成一个名为“selected”且值为“selected”的属性

请参见下面样式表中的更改:

    <select>
        <xsl:for-each select="//country/state">
            <option value="{id}">
                <xsl:if test="2 &gt; 1">
                    <!--my true-condition, will be valid for one option only-->
                    <xsl:attribute name="selected">selected</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="city"/>
            </option>
        </xsl:for-each>
    </select>

挑选出来的

对于固定字符串,您最好只执行所选的
并忘记值-of@IanRoberts:是的,没错。我会更新的。谢谢你的信息。
    <select>
        <xsl:for-each select="//country/state">
            <option value="{id}">
                <xsl:if test="2 &gt; 1">
                    <!--my true-condition, will be valid for one option only-->
                    <xsl:attribute name="selected">selected</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="city"/>
            </option>
        </xsl:for-each>
    </select>
<select>
    <xsl:for-each select="//country/state">
        <option value="{id}">
            <xsl:choose>
              <xsl:when test="2 &gt; 1"><!--my true-condition, will be valid for one option only-->
                <xsl:attribute name="selected">selected</xsl:attribute>
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>
        <xsl:value-of select="city" />
        </option>
    </xsl:for-each>
</select>