[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Just the first 'x' elements within a for-each

Subject: RE: Just the first 'x' elements within a for-each
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Mon, 17 Mar 2003 12:57:18 -0500
the first x element xslt
[Simon.Fairey@xxxxxx]
> 
> I've tried numerous connotations of for-each loops, recursive 
> functions 
> etc but for the life of me I can't seem to get something 
> which will only 
> print/process the first 'x' (in my case x is 2) elements and 
> then bail out 
> of the for-each or just simply ignore the remaining ones found.
> 

This is a good chance for you to start getting into XSLT-think mode.
Instead of limiting a loop, think of selecting just the elements you
want.  The simplest example is to put this into a template -

   <xsl:apply-templates select='element-to-work-with[3 > position()]'/>

Here you select just the first two nodes, and so whatever template
processes them only ever sees those two nodes to work on.

The most common and fundamental thing one usually does in xslt is to
select a set of nodes to work with.  Therefore, think carefully about
how to select exactly the nodes you want.

[Note that the sense of the test is reversed to avoid having to write
&lt;, which will work fine  but is harder to read]

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.