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 October 3rd, 2005, 07:17 AM
Registered User
 
Join Date: Oct 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSTL help(shopping list)

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:D
 
Old October 3rd, 2005, 08:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old October 4th, 2005, 08:31 AM
Registered User
 
Join Date: Oct 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

cool thanks will will have a look.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Shopping Portal shahkaushal ASP.NET 2.0 Basics 1 September 26th, 2008 04:26 PM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
Shopping Cart inkrajesh ASP.NET 1.0 and 1.1 Basics 2 February 28th, 2006 03:08 AM
List tablesname from database & list databasename ittorget MySQL 3 September 10th, 2005 03:06 AM
shopping cart isheikh BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 October 8th, 2004 04:20 PM





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