Divide xml data into 2 columns using xslt
I have an xslt style sheet that formats the data from my xml file into a table with a single column based on whether there is an image present or not. There is a fair amount of data so the column is too long though and i want to try splitting the current column into 2 equal columns. And idea how i can do this?
<?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>开发者_Go百科
how about something like this
<?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>
I've extracted the part that writes the content of the cells and the <xsl:choose>
part from your example to another xsl:template
called do-cell-content
精彩评论