XSLT sort on more than one child node, per parent

bloop16

New Member
I have the following XML:\[code\]<?xml version="1.0" encoding="ISO-8859-1"?><entries> <entry> <title>Entry 1</title> <prices> <price>10</price> <price>50</price> </prices> </entry> <entry> <title>Entry 2</title> <prices> <price>200</price> <price>300</price> </prices> </entry> <entry> <title>Entry 3</title> <prices> <price>70</price> <price>500</price> </prices> </entry></entries>\[/code\]Each element has more than one price tag, I want to select the MAX price, per element and use it for comparison with the rest of the elements.My xslt is:\[code\]<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <html> <body> <table border="1"> <tr> <th>Title</th> <th>Highest Price</th> </tr> <xsl:for-each select="entries/entry"> <xsl:sort select="prices/price" order="descending" data-type="number"/> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="prices/price"/></td> </tr> </xsl:for-each> </table> </body> </html></xsl:template></xsl:stylesheet>\[/code\]It doesn't work. It produces:\[code\]Title Highest PriceEntry 2 200Entry 3 70Entry 1 10\[/code\]While it should produce:\[code\]Title Highest PriceEntry 3 500Entry 2 30Entry 1 50\[/code\]Please advise me. I have to use XSLT1, so I can't really do:\[code\]<xsl:sort select="max(prices/price)" order="descending" data-type="number"/>\[/code\]...
 
Back
Top