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 March 7th, 2007, 03:49 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Newbie XSLT question


I've run into a snag with the following XSLT transformation,the goal is to output each item, quantity of the XML in a cell next to each foodgroup, if the goal is vague please inform:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes"/>
<xsl:template match="/">
    <html>
        <body>
    <h2>My Groceries</h2>
    <table border="1">
<thead>
    <tr bgcolor="#9acd32"><th scope="col" align="left">Food Group</th><th scope="col" align="left">Item</th><th scope="col" align="left">Quantity</th>
   </tr>
  </thead>
<tbody>
  <xsl:for-each select="groceryList/foodGroup">
<tr><td><xsl:value-of select="groupName"/></td><td><xsl:value-of select="item/name"/></td><td><xsl:value-of select="item/howMuch"/></td></tr>
</xsl:for-each>

</tbody>
</table>
    </body>
</html>
    </xsl:template>
</xsl:stylesheet>
Ouput So Far:
Code:
<html>
<body>
<h2>My Groceries</h2>
<table border="1">
<thead>
<tr bgcolor="#9acd32">
<th align="left" scope="col">Food Group</th><th align="left" scope="col">Item</th><th align="left" scope="col">Quantity</th>
</tr>
</thead>
<tbody>
<tr>
<td>Fruits and Vegetables</td><td>Pomegranate</td><td>2</td>
</tr>
<tr>
<td>Grains</td><td>Couscous</td><td>6 ounces</td>
</tr>
<tr>
<td>Candy</td><td>Crunchie Bar</td><td>1 gross</td>
</tr>
</tbody>
</table>
</body>
</html>
This the XML file:

Code:
<?xml version="1.0"?> 
  <groceryList> 
      <listName>My Shopping List</listName>
      <foodGroup>
          <groupName>Fruits and Vegetables</groupName>
          <item>
              <name>Pomegranate</name>
              <howMuch>2</howMuch>
          </item>
          <item>
              <name>Carrots</name>
              <howMuch>1 pound</howMuch>
          </item>
      </foodGroup>
      <foodGroup>
          <groupName>Grains</groupName>
          <item>
              <name>Couscous</name>
              <howMuch>6 ounces</howMuch>
          </item>
      </foodGroup> 
      <foodGroup>
          <groupName>Candy</groupName>
          <item>
              <name>Crunchie Bar</name>
              <howMuch>1 gross</howMuch>
          </item>
      </foodGroup> 
  </groceryList>
:D
 
Old March 7th, 2007, 04:07 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

And the snag is?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 8th, 2007, 01:06 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

The snag is outputting the additional items:
Code:
 <foodGroup>
          <groupName>Fruits and Vegetables</groupName>
          <item>
              <name>Pomegranate</name>
              <howMuch>2</howMuch>
          </item>
          <item>
              <name>Carrots</name>
              <howMuch>1 pound</howMuch>
          </item>
      </foodGroup>
Example:
Item: Carrots Quantity:1pound should be in the column beneath Item:Pomegranate and Quantity: 2, the same with the other food groups with multiple items. I'm unable to get the desired output.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie XSLT question fedehf XSLT 4 January 29th, 2008 03:09 PM
Newbie Question sionfx VS.NET 2002/2003 0 November 16th, 2006 03:32 PM
generating a table w. xslt, newbie problem themuffinman_swe XSLT 5 November 26th, 2005 01:05 PM
XSLT Newbie needs help... Should be easy fix! C4 XSLT 1 November 21st, 2005 04:11 AM
Newbie: XSLT & Scripts kwilliams XSLT 13 August 5th, 2005 11:39 AM





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