-
XSL sort and filter
This doesn't have to do with Flash, but as a Flash programmer I know that I can trust the readers of this forum to have excellent knowledge of more than just Flash. My question is with XSL:
I have a bunch of news stories in XML that store the news story and the date of the story (in 20060614 format) so that I can sort by date. I have everything set up, and in ASP I make my call to parse the XML through the XSL, which returns my results in a nice little table. Everything is fine. However, I don't want my table to keep growing as new news articles are posted to the XML. I only want to display the two most recent articles. So basically I need a way to display only the first two records in a decending sort. I tried adding an XSL:if statement but it doesn't seem to like it, I get an error. Here is what errored:
<xsl:if test="position() < 2">
</xsl:if>
Code that works, but doesn't filter just first two results:
<?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="0" width="310">
<xsl:for-each select="news/article">
<xsl:sort select="datesort" order="descending" />
xsl:if statement from above was here
<tr>
<td valign="top" width="35" style="border-right: 1px solid #cccccc; padding-right: 10px"><b><font size="1" face="Verdana" color="#616161"><xsl:value-of select="datefamiliar"/></font></b></td>
<td width="5"></td>
<td><font size="1" face="Verdana" color="#616161"><xsl:value-of select="first240"/><a href="sort.asp">more...</a></font></td>
</tr>
<tr height="6"><td colspan="5"></td></tr>
<tr height="1" bgcolor="#e9eaec">
<td colspan="3"></td>
</tr>
<tr height="6"><td colspan="3 "></td></tr>
/xsl:if statement was here
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I appreciate any help you can give.
-
Update:
I found that the xsl:if is the correct way to do this. However, it does not seem to like having a conditional on position that has a < sign. If I use = or >, it works fine. So, in order to make it work for both the first and second result, I created two xsl:if statements, one after the other, that look to see if position=1 or position=2 . I don't know why it errors out if I use the < symbol though, very odd.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|