XSL, display item[1] and item[2] in same html-table

h4x0r

New Member
I want to display XML content in a HTML table. I use the following (simplified) code to do so:\[code\]<xsl:template match="/"> <xsl:apply-templates select="/products/product"> <xsl:sort select="populariteit" order="descending" data-type="number"/> </xsl:apply-templates></xsl:template><xsl:template match="product"> <xsl:if test="position()=1"> <table> <tr> <td> <xsl:value-of select="title"/> </td> </tr> </table> </xsl:if></xsl:template>\[/code\]With the following (simplified) XML:\[code\]<products> <product> <title>Title One</title> <popularity>250</popularity> </product> <product> <title>Title Two</title> <popularity>500</popularity> </product> <product> <title>Title Three</title> <popularity>400</popularity> </product></products>\[/code\]What it does is sort the list by 'popularity', and then display the title from the first entry in the table (the most popular).Now, what I want to accomplish is to display the titles from the first two popular items. But whatever I try, the XSLT outputs them in two different tables instead of one.I've tried things like:\[code\]<xsl:template match="product"> <table> <tr> <td> <xsl:if test="position()=1"> <xsl:value-of select="title"/> </xsl:if> <xsl:if test="position()=2"> <xsl:value-of select="title"/> </xsl:if> </td> </tr> </table></xsl:template>\[/code\]But that results in two different tables; I want the titles to be displayed next to each other in the same table, while also still using the info from the sorted list.My desired HTML output would be:\[code\]<table> <tr> <td> Title Three Title Two </td> </tr></table>\[/code\]It's important I use only use one XSL to generate this output, because of certain limitations in the software I'm using.
 
Back
Top