CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Threaded View

  1. #1
    Join Date
    Oct 2005
    Posts
    1

    Question HELP. XSL problem

    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 http://www.users.on.net/~aaronjob/***1part3.xml. 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 http://www.users.on.net/~aaronjob/***1part3.xsl)

    <?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
    Last edited by awjob; October 7th, 2005 at 06:16 PM. Reason: put * where i had a URL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured