Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2010, 09:50 AM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default read first 1 to 5 records by using xsl:for-each

I want to read only first five records of the xml data by xsl. By using the xsl:for-each i am able to read all the records, but my purpose is to read only first 5 records of the xml file.


XML File :
------------------------------------------------------------------------
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<School> 
<SchoolDetails SchoolName="Name1" location="xyz1"/>
<SchoolDetails SchoolName="Name2" location="xyz2"/>
<SchoolDetails SchoolName="Name3" location="xyz3"/>
<SchoolDetails SchoolName="Name4" location="xyz4"/>
<SchoolDetails SchoolName="Name5" location="xyz5"/>
<SchoolDetails SchoolName="Name6" location="xyz6"/>
<SchoolDetails SchoolName="Name7" location="xyz7"/>
<SchoolDetails SchoolName="Name8" location="xyz8"/>
<SchoolDetails SchoolName="Name9" location="xyz9"/>
<SchoolDetails SchoolName="Name10" location="xyz10"/>
<SchoolDetails SchoolName="Name11" location="xyz11"/>
<SchoolDetails SchoolName="Name12" location="xyz12"/>
</School>

XSL:
Code:
------------------------------------------------------------------------------
<xsl:for-each select="//School/SchoolDetails"> 
<xsl:variable name="SchoolName" select="//School/SchoolDetails/@SchoolName"/>
<xsl:if test="$SchoolName">
<xsl:value-of select="//School/SchoolDetails/@SchoolName"/> 
</xsl:if>
</xsl:for-each>
 
Old October 29th, 2010, 10:34 AM
Authorized User
 
Join Date: Sep 2004
Posts: 67
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Try this...

Code:
<xsl:for-each select="//School/SchoolDetails[position() &lt; 6]">
 
Old October 29th, 2010, 11:07 AM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot.

Below code is working fine.

Code:
<xsl:for-each select="//School/SchoolDetails[position() &lt; 6]">

But in my post

Code:
<xsl:value-of select="//School/SchoolDetails/@SchoolName"/>
is pringting the 1st record for five times. But Martin Honnen
suggested that below code will print the first five records rather than printing the 1st record for 5 times.

Code:
<xsl:value-of select="@SchoolName"/>
Now i have a small problem. If the XML file is more than five records then it is fine. If the XML is having less than 5 records than i have to insert some blank values.
How i will handle that.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Read table date fill in with xsl giamba78 XSLT 5 July 22nd, 2010 09:01 AM
Connecting to a table to read and insert records mnolting Word VBA 0 October 1st, 2008 11:39 PM
How to read Array using XSL chaitanya_619 XSLT 7 May 28th, 2008 12:29 PM
How to read cdata in xsl gantait XSLT 4 February 26th, 2007 04:34 AM
Read XSL File Neal Excel VBA 1 April 7th, 2006 06:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.