|
Subject: RE: [xsl] Just the first 'x' elements within a for-each From: Simon.Fairey@xxxxxx Date: Tue, 18 Mar 2003 10:38:04 +0000 |
Thanks, I've realised the hard way that I have to get out of programming
mode and into a specific thinking mode when trying to work with XSL! More
than once I've thought "I coulda done this by now if I'd written some Perl
to grab what I want!"
One question (other than the reply to Jeni that the syntax below doesn't
seem to work in XMLSpy 5) why can you put '>' rather than '>' but you
have to use '<' rather than '<'.
Cheers
Si
"Passin, Tom" <tpassin@xxxxxxxxxxxx>
Sent by: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
17/03/2003 17:57
Please respond to xsl-list
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
cc:
Subject: RE: [xsl] Just the first 'x' elements within a for-each
[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
<, which will work fine but is harder to read]
Cheers,
Tom P
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
**********************************************************************************
This email may contain confidential material. If you were not an
intended recipient, please notify the sender and delete all copies.
We may monitor email to and from our network.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Just the first 'x' elemen, Simon . Fairey | Thread | Re: [xsl] Just the first 'x' elemen, David Carlisle |
| RE: [xsl] add new line to an html t, Jarno . Elovirta | Date | RE: [xsl] xsl:variable and creating, Jarno . Elovirta |
| Month |