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

RE: Accessing nth element

Subject: RE: Accessing nth element
From: Robert Seber <robert.seber@xxxxxxxxxxxxxxxxxx>
Date: Tue, 1 May 2001 15:01:07 +0100
xpath nth element
You can use apply-templates.  The trick is to add a select when you apply
templates:

<xsl:apply-templates select="*[position() &lt; 4]"/>

Example:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="root">
<html>
<head>
</head>
<body>
<b>Less than four:</b> <xsl:apply-templates select="*[position() &lt; 4]"/>
<br/>
<b>Fifth:</b> <xsl:apply-templates select="*[5]"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>



<?xml version="1.0" encoding="UTF-8"?>
<root>
	<item>one</item>
	<item>two</item>
	<item>three</item>
	<item>four</item>
	<item>five</item>
	<item>six</item>
</root>



> -----Original Message-----
> From: Bharat.Chintapally@xxxxxxxxxxxxxxxxx
> [mailto:Bharat.Chintapally@xxxxxxxxxxxxxxxxx]
> Sent: Tuesday, May 01, 2001 2:31 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  Accessing nth element
> 
> 
> 
> I am sorry correction: I am not using for-each but I am using 
> templates.
> Should I switch to for-each with a selection to achieve what 
> I am doing..
> 
> Thanks
> --bharat
> ---------------------------------------------------------------
> Bharat Chintapally
> CommerceQuest Inc.
> bharat.chintapally@xxxxxxxxxxxxxxxxx
> New Phone # 813-639-6478
> ---------------------------------------------------------------
> 
> 
>                                                               
>                                                                    
>                     Janning Vygen                             
>                                                                    
>                     <vygen@xxxxxxxxxxxx>               To:    
>  xsl-list@xxxxxxxxxxxxxxxxxxxxxx,                                  
>                     Sent by:                           
> Bharat.Chintapally@xxxxxxxxxxxxxxxxx                          
>             
>                     owner-xsl-list@xxxxxxxxxxxx        cc:    
>                                                                    
>                     rytech.com                         
> Subject:     Re:  Accessing nth element                  
>             
>                                                               
>                                                                    
>                                                               
>                                                                    
>                     05/01/01 09:23 AM                         
>                                                                    
>                     Please respond to xsl-list                
>                                                                    
>                                                               
>                                                                    
>                                                               
>                                                                    
> 
> 
> 
> 
> Am Dienstag,  1. Mai 2001 15:04 schrieb
> Bharat.Chintapally@xxxxxxxxxxxxxxxxx:
> > Hello all:
> >      I think I need to replace for-each in my XSLT's with 
> recursion. I am
> > interested in picking 'x' elements from 'y' (20 for each 
> page from 500
> > records) for paging. for-each is working fine, but it is overkill, I
> should
> > be able to terminate (return from as in procedural lang's) 
> processing
> when
> > I finish processing 20 records for a given page.
> >      I am trying to switch to recursion, but have a quick 
> question. Is
> > there a way to fetch an n'th element from given bunch of 
> records. For
> > example when I am processing records 20 thru records 40 out of 500
> records,
> > I would like directly fetch the record #20 from all the 
> records. Is it
> > possible..
> 
> try something like this
> 
> <xsl:for-each select="./records[position() < 20]">
> 
> not tested, but with position function inside your XPath 
> expression you
> should get the records you want.
> 
> janning
> 
> --
> Planwerk 6 /websolutions
> Herzogstraße 86
> 40215 Düsseldorf
> 
> fon 0211-6015919
> fax 0211-6015917
> http://www.planwerk6.de
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
> 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

 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-2007 All Rights Reserved.