在XSL中,我想動態生成tr的id。該id應該是我將從循環獲得的值。我將在for循環中生成一個tr。可以幫助我解決這個問題嗎?提前致謝。在XSL中爲tr動態生成id
例如,
<xsl:for-each select="books/book">
<tr id="">//I want to generate the tr with id as the value which i got for book
<td></td>
<td></td>
<tr>
</xsl:for-each>
在XSL中,我想動態生成tr的id。該id應該是我將從循環獲得的值。我將在for循環中生成一個tr。可以幫助我解決這個問題嗎?提前致謝。在XSL中爲tr動態生成id
例如,
<xsl:for-each select="books/book">
<tr id="">//I want to generate the tr with id as the value which i got for book
<td></td>
<td></td>
<tr>
</xsl:for-each>
使用<tr id="{generate-id()}">
如果您id
屬性應該設置爲<book>
元素的內部文本,你可以這樣做:
<tr>
<xsl:attribute name="id">
<xsl:value-of select="." />
</xsl:attribute>
<td></td>
<td></td>
</tr>
上面可以也可縮寫爲:
<tr id="{.}">
<td></td>
<td></td>
</tr>
是否想要每個book
節點中的內部編號或生成的編號,如1,2,....,4?
對於最後一個使用此:
<xsl:for-each select="books/book">
<tr>
<xsl:attribute name="id">
<xsl:number count="book" level="any"/>
</xsl:attribute>
<td></td>
<td></td>
</tr>
</xsl:for-each>
有關編號元素欲瞭解更多信息請看這裏:Dave Pawson XSLT FAQ或w3schools