This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Limiting a FOR-EACH loop



Dear Gurnam,
You havent explained your problem properly..
I am giving u a solution that limits the no of elements the for-each processes. You can do this using position() function..
the following is an example

xml file
--------

<elements>
<element>element1</element>
<element>element2</element>
<element>element3</element>
<element>element4</element>
<element>element5</element>
<element>element6</element>
<element>element7</element>
<element>element8</element>
</elements>

xsl
---

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
<xsl:for-each select="/elements/element[position() &lt;=5]">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

this will print the values of the first 5 elements..
I dont know if this gives a lead to your problem..please get back if you have any querries

Thanks
Vasu


From: "Gurnam Bedi" <Gurnam.Bedi@teachscape.com>
Reply-To: xsl-list@lists.mulberrytech.com
To: <xsl-list@lists.mulberrytech.com>
Subject: [xsl] Limiting a FOR-EACH loop
Date: Wed, 18 Sep 2002 12:04:27 -0400

How do I ensure that a FOR-EACH loop only iterates over the first x number
of elements. Or more generally, how can I read the values of first x number
of elements in a certain node [ex: /SEARCH/RESULTS] and ignore the rest of
the elements in the /SEARCH/RESULTS (where x itself is the value-of another
element)?

Thanks

-G


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




_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]