|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Transform list of elements to a sorted and dynamic
Interesting and very short solution, although I did not test it.
My "simple" solution (which actually works) looks like this: <xsl:variable name="Rows">3</xsl:variable> <xsl:variable name="Columns">4</xsl:variable> <xsl:template name="item-table"> <!-- As Michael, I used a variable to manage sorting the items --> <xsl:variable name="SortedItems">
<xsl:for-each select="//items">
<xsl:sort select="date" order="descending"/>
<xsl:sort select="name" order="ascending"/>
<xsl:if test="position() le $Rows * $Columns">
<xsl:sequence select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable><!-- I then walk the sorted items by the first one of each row --> <xsl:for-each select="$SortedItems/item"> <xsl:if test="(position() mod $Columns) eq 1"> <xsl:variable name="RowItems" select="following-sibling::node()[position() lt number($Columns)]"/> <tr> <!-- First Column --> <td> <!-- Add rowspan="$Columns" if there are no other items in this row --> <xsl:if test="not(count($RowItems))"> <xsl:attribute name="colspan"> <xsl:value-of select="$Columns"/> </xsl:attribute> </xsl:if> <!-- Insert formatted item data --> <xsl:apply-templates select="." mode="cell-content"/> </td> <!-- Create other columns in current row --> <xsl:for-each select="following-sibling::node()[position() lt number($Columns)]"> <td> <!-- If current node is last of current row add colspan=".." attribute --> <xsl:if test="count(following-sibling::node()[position() lt number($Columns)]) eq 0 and not(position() eq number($Columns)-1)"> <xsl:attribute name="colspan"> <xsl:value-of select="number($Columns) - position()"/> </xsl:attribute> </xsl:if> <!-- Insert formatted item data -->
<xsl:apply-templates select="." mode="cell-content"/>
</td>
</xsl:for-each>
</tr>
</xsl:if>
</xsl:for-each></xsl:template> <xsl:template match="//item" mode="cell-content"> <xsl:value-of select="name"/> </xsl:template> Probably not the easiest way, but to me it seemed to be the most ovious one. Any tips, hints, comments, disagreements? Regards, Jannis Michael Kay schrieb: First sort:
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








