I am trying to figure out how to sort the XML list of catalog numerical by price using XSL. Right now it just displays the correct information from XML. If I use the following code.
<xsl:template match="catalog">
<html>
<head>
<title>book catalog</title>
</head>
<body>
<h1>book catalogs</h1>
<table border="1">
<thead>
<tr bgcolor="red">
<td>id</td><td>author</td><td>title</td><td>generation</td><td>price</td><td>publish date</td><td>description</td>
</tr>
</thead>
<xsl:for-each select="book">
<xsl:sort data-type="number" select="price" />
<tbody>
<tr>
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="generation"/></td>
<td><xsl:value-of select="price"/></td>
<td><xsl:value-of select="publishDate"/></td>
<td><xsl:value-of select="description"/></td>
</tr>
</tbody>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
but if i change the place of xsl:sort and place it after tbody tag, it will generate error. what is difference between this two codes? is it necessary to insert xsl:sort after xsl:for-each or any thing else cause the problem?
<body>
<h1>book catalogs</h1>
<table border="1">
<thead>
<tr bgcolor="red">
<td>id</td><td>author</td><td>title</td><td>generation</td><td>price</td><td>publish date</td><td>description</td>
</tr>
</thead>
<xsl:for-each select="book">
<tbody>
<tr>
<xsl:sort data-type="number" select="price" />
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="generation"/></td>
<td><xsl:value-of select="price"/></td>
<td><xsl:value-of select="publishDate"/></td>
<td><xsl:value-of select="description"/></td>
</tr>
</tbody>
</xsl:for-each>
</table>
</body>