[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

problem with xsl:if test statement

Subject: problem with xsl:if test statement
From: Amy Huang <h.amy88@xxxxxxxxx>
Date: Mon, 17 Dec 2007 20:51:15 -0800 (PST)
 problem with xsl:if test statement
Hello, 

I'm new to xml and xsl. I need to generate one link if my query finds 
one or more records in my XML document. But I if I use "for each 
statement", the link will repeat again and again depending on how many 
records satisfy my query. E.g., if 2 records satisfy my query, the link will repeat twice like this: 

For apples, click here 
For apples, click here 

How can I generate only one link if my query finds more than one records? 

XSL: 
<?xml version="1.0" encoding="iso-8859-1"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";> 

<xsl:param name="Country" select="Mexico" ></xsl:param> 
<xsl:template match="/"> 
<html> 
<body> 
<h2>Types of Fruits</h2> 
<xsl:for-each select="Products/Fruits"> 
<xsl:if test="Country = $Country and Type = 'Apples'"> 
<a> 
<xsl:attribute name="href"> 
fruits.aspx?moi=<xsl:value-of select="$Country"/> 
</xsl:attribute> 
For apples, click here 
</a> 
<br /> 
</xsl:if> 
</xsl:for-each> 
</body> 
</html> 
</xsl:template> 
</xsl:stylesheet> 

XML: 
<Products> 
<Fruits> 
<Country>Mexico</Country> 
<Tpye>Apples</Type> 
<Tpye>Bananas</Type> 
</Fruits> 
<Fruits> 
<Country>Brazil</Country> 
<Tpye>Oranges</Type> 
<Tpye>Apples</Type> 
</Fruits> 
<Fruits> 
<Country>Peru</Country> 
<Tpye>Bananas</Type> 
<Tpye>Oranges</Type> 
</Fruits> 
</Products> 

Any help would be greatly appreciated! 

Amy Huang


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.