I am considering a similar problem with what has been described here.
Convert list to 2-D table
but with a slight wrinkle. My XML is not in any specific order, and I would like to sort it for display. For example, my XML
<items> <item>A</item> <item>C</item> <item>E</item> <item>B</item> <item>D</item> <item>
and I want my output to be (where I ignore unnamed nodes for illustrative purposes)
<table> <tr> <td>A</td> <td>C</td> <td>E</td> </tr> <tr> <td>B</td> <td>D</td> <td /> </tr> </table>
XSL I base this on the link above (I need to use XSL 1.0):
<xsl:template match="/*"> <table> <xsl:call-template name="make-columns"> <xsl:with-param name="nodelist" select="item"/> </xsl:call-template> </table> </xsl:template> <xsl:template name="make-columns"> <xsl:param name="nodelist"/> <xsl:param name="columns-number" select="3"/> <tr> <xsl:apply-templates select="$nodelist[ not(position() > $columns-number) ]"/> <xsl:if test="count($nodelist) < $columns-number"> <xsl:call-template name="empty-cells"> <xsl:with-param name="finish" select="$columns-number - count($nodelist)"/> </xsl:call-template> </xsl:if> </tr> <xsl:if test="count($nodelist) > $columns-number"> <xsl:call-template name="make-columns"> <xsl:with-param name="nodelist" select="$nodelist[ position() > $columns-number ]"/> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template match="item"> <td> <xsl:apply-templates/> </td> </xsl:template> <xsl:template name="empty-cells"> <xsl:param name="finish"/> <td/> <xsl:if test="not($finish = 1)"> <xsl:call-template name="empty-cells"> <xsl:with-param name="finish" select="$finish - 1"/> </xsl:call-template> </xsl:if> </xsl:template>
I tried to embed commands in various apply-templates, but that doesn't work.
ideas?
Jeff
Update from comments
I want to display a multi-color table with 3 columns, where the entries are in alphabetical order vertically
source share