简体   繁体   English

如何根据 for-each 循环中的索引设置元素 ID?

[英]How to set element id based on index in for-each loop?

I'm new to XSLT and I'm trying to link text boxes and check boxes in a loop.我是 XSLT 的新手,我正在尝试循环链接文本框和复选框。 The problem I have is that all check boxes are linked to the first textbox because of link between the text box id and the checkbox name.我遇到的问题是所有复选框都链接到第一个文本框,因为文本框 id 和复选框名称之间存在链接。 I read that I can get the index of the loop from using position().我读到我可以使用 position() 获取循环的索引。 But how can I get the value of position and concatenate it to the id and name of the text box and checkbox?但是如何获取 position 的值并将其连接到文本框和复选框的 id 和名称?

Any suggestions?有什么建议么?

<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>

Use an attribute value template in the form of <input type="checkbox" name="plantName{position()}"/> to compute the name as a concatenation of the static string plantName and the current value of position() .使用<input type="checkbox" name="plantName{position()}"/>形式的属性值模板将名称计算为 static 字符串plantNameposition()的当前值的串联。

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

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