Pmint
12-14-2007, 10:54 PM
Hello,
I'm now 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 3 records satisfy my query, the URL will repeat 3 times like this:
For apples, click here
For apples, click here
For apples, click here
How can I generate only one link for this purpose? What query statement shall I use? Any help would be appreciated.
Here’s the 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>
Here’s the xml document:
<Products>
<Fruits>
<Record-Number>72</Record-Number>
<Country>Mexico</Country>
<Tpye>Apples</Type>
<Tpye>Bananas</Type>
</Fruits>
<Fruits>
<Record-Number>102</Record-Number>
<Country>Brazil</Country>
<Tpye>Oranges</Type>
<Tpye>Apples</Type>
</Fruits>
<Fruits>
<Record-Number>80</Record-Number>
<Country>Peru</Country>
<Tpye>Bananas</Type>
<Tpye>Oranges</Type>
</Fruits>
<Fruits>
<Record-Number>98</Record-Number>
<Country>India</Country>
<Tpye>Pears</Type>
<Tpye>Apples</Type>
</Fruits>
</Products>
I'm now 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 3 records satisfy my query, the URL will repeat 3 times like this:
For apples, click here
For apples, click here
For apples, click here
How can I generate only one link for this purpose? What query statement shall I use? Any help would be appreciated.
Here’s the 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>
Here’s the xml document:
<Products>
<Fruits>
<Record-Number>72</Record-Number>
<Country>Mexico</Country>
<Tpye>Apples</Type>
<Tpye>Bananas</Type>
</Fruits>
<Fruits>
<Record-Number>102</Record-Number>
<Country>Brazil</Country>
<Tpye>Oranges</Type>
<Tpye>Apples</Type>
</Fruits>
<Fruits>
<Record-Number>80</Record-Number>
<Country>Peru</Country>
<Tpye>Bananas</Type>
<Tpye>Oranges</Type>
</Fruits>
<Fruits>
<Record-Number>98</Record-Number>
<Country>India</Country>
<Tpye>Pears</Type>
<Tpye>Apples</Type>
</Fruits>
</Products>