0

我正在尝试使用解析简单 xml 文件的 xsl 设计一个表单;像这样:

<tests>
    <agent ID="1" Name="Name 1"  />
    <agent ID="2" Name="Name 2"  />
    <agent ID="3" Name="Name 3"  />
</tests>

和 xsl 文件:

<form action="." method="post"  >
        <xsl:for-each select="tests">
        <table >
            <tr>
                <th></th>
                <th>ID</th>
                <th>Name</th>
            </tr>
            <xsl:for-each select="agent">
                <tr>
                    <td><input type="checkbox" name="checkbox1" value="" /> </td>
                    <td><xsl:value-of select="@ID"/></td>
                    <td><xsl:value-of select="@Name"/></td>
                </tr>
            </xsl:for-each>
        </table>
            <input type="submit" value="Delete"/>
        </xsl:for-each>
        </form>

我希望复选框的值是 ID 值。(<xsl:value-of select="@ID"/>)。但我不能在复选框标签内使用这个标签。我该怎么办?

4

2 回答 2

4

与其他地方提到的元素一样,属性值模板<xsl:attribute>也值得学习,因为它们通常可以帮助简化您的 XSLT 代码。这些允许您将表达式直接放在属性中

<input type="checkbox" name="checkbox1" value="{@Value}" />

花括号 { } 表示这是一个“AVT”并包含一个要计算的表达式。

<xsl:attribute>如果您想要基于 XML 中的某些值的动态属性名称,您甚至可以在其中使用它们。

<xsl:attribute name="{$attrname}">
于 2012-08-15T07:50:48.067 回答
0

<xsl:attribute>将允许您向标签添加任意属性。

xsl:attribute元素可用于向结果元素添加属性,无论是由样式表中的文字结果元素还是由诸如xsl:element.

<picture>
  <xsl:attribute name="source">foo</xsl:attribute>
</picture> 
于 2012-08-15T07:09:16.987 回答