Subject: Re: [xsl] need to limit a For:each loop From: Jon Gorman <jonathan.gorman@xxxxxxxxx> Date: Thu, 5 May 2005 10:44:58 -0500 |
> the current output can be seen here > http://www.discountfirepagers.com/rss2/default.asp > as you can see there are many articles ... Word of advice, I know that some people on the list don't like to follow links out for information for several reasons: It's a potential security issue, it usually means a huge input/output (doesn't seem to be the case this time), and it's just another step. Usually you get better mileage with smaller examples in the body of the email.. > I wish to limit the articles to just 5 items. however i can't figure how > to modify the XSL to do that for me > i know i have to break the for:each somehow or change it to a specified > loop but can't find any info on how to do this Because there isn't really any "break". XSLT is a descriptive language, much more akin to SQL. If you just want the first five, say so. <!-- you really should be climbing down the tree, not using //*. --> <!-- lets create a node-group of just the items --> <xsl:variable name="items" select="//*[local-name()='item']"/> <!-- now for ever node in item that has a position less than six do ... --> <xsl:for-each select="$items[position() < 6]"> whatever you want to do in the loop > </xsl:for-each> You could probably be happy and stop there. But I still don't think it's quite a spiffy as it could be. Sorry I don't have the time now to rework it (need to work on my own rss script). Also, one last comment. The templates you have seem a little poorly chosen. Without looking at it too much here's what happens. You get to the root element. Most specific template matching is with match="/". Now you apply templates to all the children (in this case the element node "rss"). Only one template matches: "*". No templates are called or named in this template so processing stops. you might as well move all your code into the match="/". If you get into the habit of using that type of set up (matching="*" and using "//*" inside the template) you'll get burned at some point and start getting duplicates. Some suggestions: Use more templates and apply templates. Check out namespaces and how to use them. local-name() might be necessary but most likely not. I'd advise using a command-line xslt processor like Saxon. I'm willing to bet you are using a browser to view your results right? I find Saxon and the command line much , much nicer for debugging. Dave Pawson's FAQ for this list is excellent http://www.dpawson.co.uk/xsl/index.html. Also, the archives tend to have answers to most basic questions. I'm willing to bet there are plenty of materials and examples out there on just transforming RSS with XSLT. Sorry I don't have more time to give examples. Try creating scripts that crawl up and down the rss just for practice, or create recursive functions. Those seem good ways for getting into some of the more complex issues. Jon Gorman
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] need to limit a For:each , Angel Gavin | Thread | [xsl] XSL for WordML -> specific HT, Stephen |
RE: [xsl] need to limit a For:each , Angel Gavin | Date | Re: [xsl] A challenge.. Group Perio, Wendell Piez |
Month |