【问题标题】:How do you populate a dropdownlist using XSLT如何使用 XSLT 填充下拉列表
【发布时间】:2017-08-05 15:53:31
【问题描述】:

我可以创建一个downdownlist。但是,我无法使用 XML 数据向其中填充任何内容。谁能帮我解决这个问题?谢谢!

这是 XML 代码

<group name="Security / PDPA">
  <section name="Control" db_field_name="control_score">
    <field is_admin_field="N" required="Y">
      <question_title>Verify customer's details when necessary</question_title>
      <type>List</type>
      <db_field_name>verify_customers_details_when_necessary_control</db_field_name>
      <options>
        <item score="2">Yes</item>
        <item score="0">No</item>
        <item score="2">No with reason</item>
      </options>
      <db_field_length>14</db_field_length>
      <additional_comment/>
    </field></section></group>

这是 XSLT 代码

 <select name="form">
      <xsl:for-each select="form/fieldset/group/section/field/options">
        <option>
          <xsl:attribute name="value">
            <xsl:value-of select="item"/>
          </xsl:attribute>
        </option>
      </xsl:for-each>
      </select>

【问题讨论】:

    标签: asp.net xml xslt


    【解决方案1】:

    我假设您没有显示完整的 XML,因为您在 xsl:for-each 中的 Xpath 表达式正在寻找 form/fieldset/group/section/field/options,但初始的 formfieldset 都没有显示在您的 XML 中。

    考虑到这一点,问题可能是因为您选择了带有xsl:for-eachoptions 元素,但只有其中一个。您应该选择 item 元素,因为看起来您想为每个项目输出一个 &lt;option&gt; 标记

      <xsl:for-each select="form/fieldset/group/section/field/options/item">
        <option>
          <xsl:attribute name="value">
            <xsl:value-of select="@score"/>
          </xsl:attribute>
          <xsl:value-of select="." />
        </option>
      </xsl:for-each>
    

    或者更好的是,使用属性值模板来缩短代码

      <xsl:for-each select="form/fieldset/group/section/field/options/item">
        <option value="{@score}">
          <xsl:value-of select="." />
        </option>
      </xsl:for-each>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-08
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      相关资源
      最近更新 更多