[英]XSL create html header with rowspan = number of iterations in for-each loop
What I am trying to do is format a table header to span the number of rows entered in a for-each loop. 我正在尝试做的是格式化表头以覆盖在for-each循环中输入的行数。 I thought to set up a separate for-each loop to count the number of entries and increment a variable to use later, but I guess that does not work with xsl. 我曾想建立一个单独的for-each循环来计算条目数并增加一个变量以供以后使用,但是我想这不适用于xsl。 This is my first attempt at using it. 这是我第一次尝试使用它。 Here is how I tried to set it up: 这是我尝试设置的方法:
<xsl:variable name= "increment" select="0" />
<xsl:for-each select = "/keyboard/brand">
<xsl:for-each select = "/keyboard/brand/model">
<xsl:variable name="increment" select="$increment + 1" />
</xsl:for-each>
<tr>
<th rowspan = $increment><xsl:value-of select = "brand"/></td>
<xsl:for-each select = "/keyboard/brand/model">
<td><xsl:value-of select = "keytype"/></td>
<td><xsl:value-of select = "backlit"/></td>
</tr>
<tr>
</xsl:for-each>
<xsl:variable name= "increment" select="0" />
</xsl:for-each>
Here is a portion of the xml I am working with: 这是我正在使用的xml的一部分:
<keyboard>
<brand>Logitech
<model>MK270
<keytype>Membrane</keytype>
<backlit check = "no">Qwerty</backlit>
<backlit check = "no">Numpad</backlit>
<interface>Wireless USB</interface>
<batterypowered>Yes</batterypowered>
<programmablekeys location = "none">None</programmablekeys>
<launchkeys location = "top">Media Controls</launchkeys>
</model>
<model>K350
<keytype>Membrane</keytype>
<backlit check = "no">Qwerty</backlit>
<backlit check = "no">Numpad</backlit>
<interface>Wireless USB</interface>
<batterypowered>Yes</batterypowered>
<programmablekeys location = "none">None</programmablekeys>
<launchkeys location = "side">Zoom Controls</launchkeys>
<launchkeys location = "top">Media Controls</launchkeys>
</model>
<model>G110
<keytype>Membrane</keytype>
<backlit check = "yes">Qwerty</backlit>
<backlit check = "yes">Numpad</backlit>
<interface>USB 2.0</interface>
<batterypowered>No</batterypowered>
<programmablekeys location = "side">12 programmable G-keys</programmablekeys>
<launchkeys location = "top">Audio/Mic/Media Controls</launchkeys>
</model>
</brand>
What I would like to do is have the Brand span all of the rows that the models take up. 我想做的是让品牌覆盖模型占用的所有行。 I am going to put each model in it's own row. 我将把每个模型放在自己的行中。
I have read that I am supposed to use the position() function instead of how I tried to handle it, but I am not sure how I would implement that for this situation, since I would need to determine the rowspan size before position() would finish counting. 我已经读过我应该使用position()函数而不是尝试使用它的方法,但是我不确定在这种情况下如何实现该功能,因为我需要在position()之前确定行跨大小将完成计数。
I am sure there are other bugs I will have to work out, like I haven't quite worked out how to not add the last tr on the final iteration, but that will come later. 我确定还有其他错误需要解决,例如我还没有弄清楚如何不在最终迭代中添加最后一个tr,但这将在以后出现。 So will the rest of the data I need to add. 因此,我需要添加的其余数据也会如此。
我还不了解您想要哪种表结构,但是在<xsl:for-each select = "/keyboard/brand">
您可以使用例如<th rowspan="{count(model)}">
来获得例如<th rowspan="3">
对于您的示例, <th rowspan="3">
是一个跨越三行的单元格,然后您可能希望在其中用内部<xsl:for-each select="model"><tr><td>...</td>...</tr></xsl:for-each>
填充它们<xsl:for-each select="model"><tr><td>...</td>...</tr></xsl:for-each>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.