我有一个xslt样式表,它根据是否存在图像,将我的xml文件中的数据格式化为具有单个列的表。有相当数量的数据,因此列太长了,我想尝试将当前列拆分为2个相等的列。并想出我怎么做到这一点?
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border="0" bordercolor="#606060" style="width:200px">
<tr bgcolor="white" width="200px">
</tr>
<xsl:for-each select="NewDataSet/Manufacturer">
<tr>
<xsl:choose>
<xsl:when test="Image = 'none'">
<td bgcolor="#dfdfdf">
<a href="Vehicles.aspx?Manufacturer={ManufacturerID}" style="text-decoration:none;" runat="server">
<xsl:value-of select="Manufacturer"/>
</a>
</td>
</xsl:when>
<xsl:otherwise>
<td>
<a href="Vehicles.aspx?Manufacturer={ManufacturerID}" style="text-decoration:none;" runat="server">
<im alt="{Manufacturer}" src="Images/Manufacturers/{Image}" style="border-width: 0px; width: 50px; "/>
</a>
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</xsl:template>
答案 0 :(得分:2)
这样的事情
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border="0" bordercolor="#606060" style="width:200px">
<tr bgcolor="white" width="200px">
</tr>
<tr>
<xsl:for-each select="NewDataSet/Manufacturer">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">
<!-- so essentialy on even numbered elements process the current and next elements -->
<td>
<xsl:call-template name="do-cell-content">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</td>
<td>
<xsl:call-template name="do-cell-content">
<xsl:with-param name="node" select="../Manufacturer[position()+1]"/>
</xsl:call-template>
</td>
<xsl:when>
</xsl:choose>
</xsl:for-each>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
我已将提取单元格内容的部分和示例中的<xsl:choose>
部分提取到名为xsl:template
的另一个do-cell-content