【问题标题】:Dynamic Colspan for td in xsltxslt 中 td 的动态 Colspan
【发布时间】:2012-10-27 07:19:14
【问题描述】:
我有……
<tr>
<xsl:variable name="noofrows" select="count(ChargeGroupsVo)"></xsl:variable>
<td colspan="$noofrows" style="border-top: 1px solid black;padding: 5px;"></td>
</tr>
这里
ChargeGroupsVo 是具有大约 8 个计数的数据类
我想要计数 8 作为 colspan....
xslt 的输出类型是 HTML
如何做到这一点...
【问题讨论】:
标签:
asp.net
xslt
xslt-2.0
【解决方案1】:
您需要在此处使用“属性值模板”。
而不是这样做......
<td colspan="$noofrows" style="border-top: 1px solid black;padding: 5px;"></td>
你需要这样做
<td colspan="{$noofrows}" style="border-top: 1px solid black;padding: 5px;"></td>
花括号 { } 表示它是要计算的表达式,而不是要按字面输出的内容。
事实上,你根本不需要这个变量。你也可以这样做:
<td colspan="{count(ChargeGroupsVo)}" style="border-top: 1px solid black;padding: 5px;"></td>
【解决方案2】:
我这样做了...
<td>
<xsl:for-each select="ChargeGroupNames">
<xsl:variable name="norows" select="count(ChargeGroupsVo)"></xsl:variable>
<xsl:if test="$norows > 1">
<xsl:attribute name="colspan">
<xsl:value-of select="$norows + 2"/>
</xsl:attribute>
</xsl:if>
</xsl:for-each>
</td>
动态添加的属性和值......