Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

for-each statement

Status
Not open for further replies.

ksbrace

Programmer
May 13, 2000
501
US
Hello,
I'm working through a tutorial in the Deitel & Deitel book. I'm doing a for-each statement, but my values are not showing up. The only thing that is showing up is my thead info. I have pasted my two files below. Any advice would be greatly appreciated! Thanks in advance
Kelly

ex20_9.xml file
Code:
<?xml version=&quot;1.0&quot;?>
<?xml:stylesheet type = &quot;text/xsl&quot; href = &quot;ex20_10.xsl&quot;?>
<!--Kelly S. Brace: ksb8327-->
<!--Example 20_9.xml-->

<nutritionFacts>

	<productName>Grandma Deitel's Cookies</productName>

	<servingSize> 1 package</servingSize>

	<nutrients>
	
		<nutrient name = &quot;calories&quot;>
			<value>260</value>
		</nutrient>
	
		<nutrient name = &quot;fatCalories&quot;>
			<value>100</value>
		</nutrient>
	
		<nutrient name = &quot;sodium&quot;>
			<value>210 milligrams</value>
		</nutrient>
	
		<nutrient name = &quot;cholesterol&quot;>
			<value>5 milligrams</value>
		</nutrient>
	
		<nutrient name = &quot;protein&quot;>
			<value>5 grams</value>
		</nutrient>
	
		<nutrient name = &quot;fat&quot;>
			<value>11 grams</value>
		</nutrient>
	
		<nutrient name = &quot;saturatedFat&quot;>
			<value>2 grams</value>
		</nutrient>
	
		<nutrient name = &quot;carbohydrates&quot;>
			<value>36 grams</value>
		</nutrient>
	
		<nutrient name = &quot;fiber&quot;>
			<value>2 grams</value>
		</nutrient>
	
		<nutrient name = &quot;sugar&quot;>
			<value>5 grams</value>
		</nutrient>
	
	</nutrients>

</nutritionFacts>
ex20_10.xsl file
Code:
<?xml version = &quot;1.0&quot;?>

<!--Kelly S. Brace: ksb8327-->

<xsl:stylesheet version = &quot;1.0&quot;
    xmlns:xsl = &quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;>[/URL]
    
    <xsl:output method = &quot;html&quot; omit-xml-declaration = &quot;no&quot;
    	doctype-system = &quot;[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;[/URL]
    	doctype-public = &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;/>
    
    <xsl:template match = &quot;/&quot;>
    
	    <html xmlns=&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;>[/URL]
		
			<head>
			
		    	<title>Nutritional Facts for Grandma Dietel's Cookies</title> 
			
			</head>
			
			<body>
			
				<table border = &quot;1&quot;>
			
					<thead>
			
						<tr>
			
							<th>Nutrient</th>
							<th>Value</th>
			
						</tr>
			
					</thead>
					
					<xsl:for-each select = &quot;nutrients/nutrient&quot;>
			
						<tr>
			
							<td><xsl:value-of select = &quot;@name&quot;/></td>
							<td><xsl:value-of select = &quot;value&quot;/></td>
			
						</tr>
			
					</xsl:for-each>
			
				</table>
			
			</body>
		
		</html>
	
	</xsl:template>

</xsl:stylesheet>
 
I figured out what I was doing wrong. I had the wrong value in the <xsl:template match = &quot;/&quot;> tag, once I changed it to:
<xsl:template match = &quot;nutritionFacts&quot;> my data showed up.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top