I am trying to get my head around the functions etc in xslt with xml. I have made a dummy xml file
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="books.xslt"?>
<books>
<book>
<title>Hello Dolly</title>
<author>John Thumb</author>
<readers>
<young_readers>17</young_readers>
<older_readers>23</older_readers>
<total_readers>40</total_readers>
</readers>
</book>
<book>
<title>Goodbye John Thumb</title>
<author>Dolly Smith</author>
<readers>
<young_readers>12</young_readers>
<older_readers>3</older_readers>
<total_readers>15</total_readers>
</readers>
</book>
<book>
<title>A Boat Afloat</title>
<author>Mike Sailor</author>
<readers>
<young_readers>19</young_readers>
<older_readers>22</older_readers>
<total_readers>41</total_readers>
</readers>
</book>
<book>
<title>Five Drummers Drumming</title>
<author>Carol Christmas</author>
<readers>
<young_readers>11</young_readers>
<older_readers>2</older_readers>
<total_readers>13</total_readers>
</readers>
</book>
</books>
and what I wish to do is manipulate the reader's data to get different output. For example, sort all the young readers, find the highest and see which book this figure belongs to. The result for that would be "A Boat Afloat". I am totally new to XML and XSLT and what I know about other language functions just don't work here. This is my XSLT for the sum of readers...
<?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>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>books</title>
</head>
<body>
<h2>Books and Their Readers</h2>
<p>Total Yound Readers<xsl:text> - </xsl:text><xsl:value-of select="sum((//young_readers)[.!=''])"/></p>
<p>Total Older Readers<xsl:text> - </xsl:text><xsl:value-of select="sum((//older_readers)[.!=''])"/></p>
<p>Grand Total Readers<xsl:text> - </xsl:text><xsl:value-of select="sum((//total_readers)[.!=''])"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
This all works. I just want to learn the functions a bit better so any hints will help. I also feel there might be a way of adding up the readers per book without hard coding the results for total_readers. Thanks in advance