Rui Barbosa Rui Barbosa - 6 months ago 13
HTML Question

XSLT sort by two elements; use second if first is repeated

Basically I have a XML with the following structure and I want to make a XSL Transformation from XML to HTML. The important thing about that is that I want to have a table with all the information about a program sorted by date. The catch is that, if the

elements are the same, you should sort by
. I have no idea how to pull that off.

<program channel="FOX" season="9" episode="2">
<resume>Something about a murder, idk...</resume>
</program >
... <!-- program can repeat -->


The sort key specification allows for multiple xsl:sort elements for precisely this use case:

[Definition: Within a sort key specification, each xsl:sort element defines one sort key component.] The first xsl:sort element specifies the primary component of the sort key specification, the second xsl:sort element specifies the secondary component of the sort key specification and so on.

So, just specify a second xsl:sort for the time element:

<xsl:sort select="date"/>
<xsl:sort select="time"/>