XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Venkata satishSubject: Display x number of items which satisfy a condition
Author: Venkata satish
Date: 31 Mar 2009 07:02 AM
Hi,

I have a situation where I have some 100 items in an XML and I want to show 10 items which satisfy a condition.

Sample XML:
<response>
<doc>
<str name="ID">1</str>
<str name="STATUS">1</str>
</doc>
<doc>
<str name="ID">2</str>
<str name="STATUS">2</str>
</doc>....
<doc>
<str name="ID">100</str>
<str name="STATUS">2</str>
</doc>

I want to display 10 ids which have status =1.

Thanks in advance.

Postnext
Minollo I.Subject: Display x number of items which satisfy a condition
Author: Minollo I.
Date: 31 Mar 2009 09:45 PM
Originally Posted: 31 Mar 2009 07:22 PM
One way to do that is something like this:
<result>
<xsl:for-each select="//doc[str[@name='STATUS']='1']">
<xsl:if test="position() &lt;= 10">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</result>

Postnext
Venkata satishSubject: Display x number of items which satisfy a condition
Author: Venkata satish
Date: 31 Mar 2009 09:10 PM
Hi,

I tried this method, but I do not have exact 10 results. Also, if first 10 nodes does not satisfy the condition, I will not have anything.

Postnext
Minollo I.Subject: Display x number of items which satisfy a condition
Author: Minollo I.
Date: 31 Mar 2009 09:18 PM
Don't know what XSLT processor you are using, but if you are using any decent one and the problem is as you described, you will indeed get 10 entries (or less), no matter if the first million entries don't satisfy the condition.

Postnext
Venkata satishSubject: Display x number of items which satisfy a condition
Author: Venkata satish
Date: 31 Mar 2009 09:35 PM
Ok, it returns results, but I need to display exact 10 results.

Posttop
Minollo I.Subject: Display x number of items which satisfy a condition
Author: Minollo I.
Date: 31 Mar 2009 09:44 PM
I believe the answers you were looking for have been given to you.

For future generic XSLT questions, please use discussion lists that are not product specific, like the one hosted by mulberrytech dot com

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.