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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.