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 May 30th, 2012, 03:26 PM
Registered User
 
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
 
Old May 30th, 2012, 03:36 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old May 30th, 2012, 03:48 PM
Registered User
 
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
 
Old May 30th, 2012, 05:17 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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





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





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