[英]How to set element id based on index in for-each loop?
我是 XSLT 的新手,我正在嘗試循環鏈接文本框和復選框。 我遇到的問題是所有復選框都鏈接到第一個文本框,因為文本框 id 和復選框名稱之間存在鏈接。 我讀到我可以使用 position() 獲取循環的索引。 但是如何獲取 position 的值並將其連接到文本框和復選框的 id 和名稱?
有什么建議么?
<xsl:for-each select="plants">
<tr>
<td>
<input type="text" class="form-control" id= "plantName" name="//pn:plants/pn:plantName" disabled="disabled" maxlength="16"/>
</td>
<td>
<div class="checkbox">
<label>
<input type="checkbox" name="plantName"/> Edit name
</label>
</div>
</td>
</tr>
</xsl:for-each>
使用<input type="checkbox" name="plantName{position()}"/>
形式的屬性值模板將名稱計算為 static 字符串plantName
和position()
的當前值的串聯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.