Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 30th, 2012, 03:26 PM
Registered User
Points: 14, Level: 1
Points: 14, Level: 1 Points: 14, Level: 1 Points: 14, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT displays too many results

Hi,
I'm new at this and I appreciate any help you can give.

Example XML
Code:
<CATALOG>
	<CD>
		<TYPE>45 rpm</TYPE>
		<TITLE>Empire Burlesque</TITLE>
		<PRICE>10.90</PRICE>
	</CD>
	<CD>
		<TYPE>75 rpm</TYPE>
		<TITLE>Hide your heart</TITLE>
		<PRICE>9.90</PRICE>
	</CD>
	<CD>
		<TYPE>45 rpm</TYPE>
		<TITLE>Greatest Hits</TITLE>
		<PRICE>9.90</PRICE>
	</CD>
	<CD>	
		<TYPE>75 rpm</TYPE>	
		<TITLE>Still got the blues</TITLE>
		<PRICE>10.20</PRICE>
	</CD>
</CATALOG>
I have an XSLT for-each for each CD.
How do I get it to stop once it finds a 45 rpm.
The first time I want it to find the first 45 rpm, but the next time I want it to find the second, or third.


OUTPUT IS LIKE THIS KIND OF


Page 1
Blah Blah Blah
Blah Blha etc.

Price $10.90

Page 2
Blah Blah Blah
Blah Blha etc.

Price $9.90

I'm doing something like this but it always brings back both prices for the 45 rpm
Code:
<xsl:for-each select="/CATALOG/CD"/>
     <xsl:if test="type='45 rpm'"/>
           do some stuff here
     </xsl:if>
</xsl:for-each>
I know there is no BREAK an no LOOPS or VARIABLES, but I want it to break.

Any assistance is going to really help.
Thanks,
Mike
Reply With Quote
  #2 (permalink)  
Old May 30th, 2012, 03:36 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you only want to process the first qualifying element, you don't need a for-each. Just do

Code:
<xsl:apply-templates select="/CATALOG/CD[type='45rpm'][1]"/>
and then write a template rule to process the selected CD.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #3 (permalink)  
Old May 30th, 2012, 03:48 PM
Registered User
Points: 14, Level: 1
Points: 14, Level: 1 Points: 14, Level: 1 Points: 14, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I bought your book. I'm not smart enough yet to understand it however.

Thanks for the quick reply.

What does the [1] do?

Mike
Reply With Quote
  #4 (permalink)  
Old May 30th, 2012, 05:17 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If XX is a node-set, then XX[1] selects the first node in the node-set. Usually the first node in document order, unless XX is a reverse axis, e.g. preceding-sibling::*[1].
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dropdown displays wrong on IE DanCern BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 June 22nd, 2011 08:31 AM
How do i create a subform which displays query results? tangwt Access 1 April 6th, 2009 08:31 AM
how do i create a subform which displays query results? tangwt Access 1 March 26th, 2009 02:34 PM
Edit Query Results in Results Grid druid2112 SQL Server 2005 1 June 28th, 2007 08:49 AM
Webservice displays only 1 instead of ALL results eli2003 .NET Web Services 0 September 9th, 2003 12:33 PM



All times are GMT -4. The time now is 01:12 PM.


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