|
Subject:
|
XSTL help(shopping list)
|
|
Posted By:
|
awjob
|
Post Date:
|
10/3/2005 7:17:05 AM
|
hello, I am haveing a problem with a XSL file. I am trying to add up all the quanties of each of the items and compile a shopping list. here is some of my xml file
<menu> <recipe> <head> <title>$20,000 Prize-Winning Chili</title> </head> <ingredients> <ing> <amt> <qty>2.5</qty> <unit>pound</unit></amt> <item>Lean ground chuck</item></ing> <ing> <amt> <qty>1</qty> <unit>pound</unit></amt> <item>Lean ground pork</item></ing> <ing> <amt> <qty>1</qty> <unit>cup</unit></amt> <item>Finely chopped onion</item></ing> <ing> <amt> <qty>4</qty> <unit/></amt> <item>Garlic cloves; finely chpd.</item></ing> </menu>
The full XML file is located here (site down) I want it to list all the items once(if they come up more than that) and give the sum of the quanty(the qty tag). eg(quanty to come form qty tag): Chicken 400g Milk 100ml
My XSL code: (full listing (site down))
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xslutput method="html"/> <xsl:key name="tempItem" match="recipeml/menu/recipe/ingredients/ing" use="item"/> <xsl:template match="/"> <xsl:apply-templates select="recipeml/menu"/> </xsl:template> <xsl:template match="menu"> <html> <head> <title>Shopping List</title> </head> <body> <xsl:apply-templates select="//ing"/> </body> </html> </xsl:template> <xsl:template match="//ing"> <li> Item: </li> <xsl:for-each select="./item[generate-id()= generate-id(key('tempItem',item)[1])]"> <xsl:value-of select="./item"/> Count: <xsl:value-of select="count(/item=current())"/> Generated ID: <xsl:value-of select="generate-id(.)"/> </xsl:for-each> </xsl:template> <xsl:template match="*|text()"/> </xsl:stylesheet>
I have been pulling my hair out for days now over it can someone help me. Thanks to anyone who even has a go at it
|
|
Reply By:
|
mhkay
|
Reply Date:
|
10/3/2005 8:54:25 AM
|
A standard grouping problem: see http://www.jenitennison.com/xslt/grouping
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
awjob
|
Reply Date:
|
10/4/2005 8:31:05 AM
|
cool thanks will will have a look.
|