I’m using XSLT to get data out of a feed. Currently I use this block of code, which simply picks the first item out of the feed. I changed it a bit so it applies to this sample XML.
<?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>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="/">
<xsl:value-of select="catalog/book/author"/>
</xsl:template>
</xsl:stylesheet>
I want to sort the xml by price, and then pick the author associated with the highest priced book. I’ve tried all kind of things, but I can’t seem to figure it out.
The current output is “Gambardella, Matthew”, but I need it to be “Galos, Mike”.
you can specify an
<xsl:sort>inside apply-templates, like so:and then in your little ‘book’ template, use the
position()to filter out only the first book node