Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2003
    Location
    New Jersey, USA
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    XSL-can't get all my data to appear

    I'm having a problem getting all the ingredients to appear when I try to select them from my xml document.

    If I use <td><xsl:value-of select="ingredients"/><br/></td>, all of the ingredients appear, but I can't figure out how to get a line break between each ingredient.

    If I use <td><xsl:value-of select="measure"/><br/></td>, then only the first ingredient appears.

    Can someone offer advice on how to pull all the ingredients from my xml document (recipe.xml) so the ingredients are neatly listed?

    The codes for each file are below.

    Thank you
    Stacey

    <?xml version="1.0" ?>
    <?xml-stylesheet type="text/xsl" href="recipestyle.xsl"?>

    <recipe_file>

    <recipe>
    <category>dinner</category>
    <name>Lentils Linguine</name>
    <ingredients>
    <measure>Lentils</measure>
    <measure>oil</measure>
    <measure>garlic</measure>
    <measure>linguine</measure>
    </ingredients>
    <directions>
    Boil lentils until cooked in enough water.In separate pot cut linguine in 1" pieces and cook in water with 1 tsp salt. Drain. Add linguine to lentils. In small skillet put 2 to 3 Tbls olive oil and 3 cloves of garlic until garlic is light brown. Cut garlic in small pieces before browning in hot oil. Add to lentils and linguine.
    </directions>
    </recipe>

    <recipe>
    <category>dessert</category>
    <name>Lemon Lush</name>
    <ingredients>
    <measure>2 cups flour</measure>
    <measure>1 cup butter</measure>
    <measure>1 cup chopped nuts</measure>
    </ingredients>
    <ingredients>
    <measure>2 pkgs lemon pudding (NOT instant)</measure>
    <measure>1 8oz. pkg cream cheese</measure>
    <measure>1 cup powdered sugar</measure>
    <measure>2 cups Cool Whip</measure>
    </ingredients>
    <directions>
    Mix flour, butter and nuts. Press into an oblong baking dish. Bake at 350&#176; until light brown. Cook pudding as directed on box but cut back on water by 1/4 cup. Refrigerate overnight.

    Next Day:
    Mix cream cheese and powdered sugar until creamy. Fold in 1 cup Cool Whip. Pour mixture over cool crust.

    Mix lemon pudding and spread over cream cheese mixture. Top with 1 cup of Cool Whip.
    </directions>
    </recipe>

    <recipe>
    <category>dessert</category>
    <name>Cream Puffs</name>
    <ingredients>
    <measure>1 cup water</measure>
    <measure>4 eggs</measure>
    <measure>1/2 cup butter</measure>
    <measure>2 pkgs vanilla pudding for filling</measure>
    <measure>1 cup flour</measure>
    <measure>Chocolate glaze</measure>
    </ingredients>
    <directions>
    Heat over to 400&#176;
    Heat water and butter to a rolling boil.
    Stir in flour.
    Stir vigorously over low heat about 1 minute or until mixture forms a ball. Remove from heat. Beat in eggs all at once, continue beating until smooth. Drop dough by tablespoonfuls 3 inches apart onto ungreased cookie sheet. Bake 30 - 35 minutes. When cool, cut in half, fill with vanilla pudding and glaze. Makes 20-24 puffs.
    </directions>
    </recipe>


    <recipe>
    <category>dessert</category>
    <name>Chocolate Glaze</name>
    <ingredients>
    <measure>2 oz. unsweetened chocolate</measure>
    <measure>2 tsp butter</measure>
    <measure>1.5 cups 10X sugar</measure>
    <measure>2 - 4 Tbls hot water</measure>
    </ingredients>

    <directions>
    Carefully melt chocolate and butter over low heat.
    Remove from heat and stir in sugar and 1 Tbls of water at a time.
    </directions>
    </recipe>


    <recipe>
    <category>dinner</category>
    <name>Peppers &#38; Onions Wrap</name>
    <ingredients>
    <measure>2 red peppers</measure>
    <measure>1 green pepper</measure>
    <measure>1 large onion</measure>
    <measure>garlic salt</measure>
    <measure>worcestershire sauce</measure>
    </ingredients>
    <directions>
    Saut&#233; peppers and onions until tender. Stir in worcestershire sauce and garlic salt. Place in seasoned or plain tortilla. Serves 4 people.
    </directions>
    </recipe>


    <recipe>
    <category>dessert</category>
    <name>Chocolate Lover's Chocolate Mousse Pie</name>

    <ingredients>
    <measure>1 cup graham cracker crumbs</measure>
    <measure>1/3 cup baking cocoa</measure>
    <measure>1/4 cup granulated sugar</measure>
    <measure>1/3 cup butter, melted</measure>
    <measure>16 oz. semi-sweet chocolate morsels, divided</measure>
    <measure>2 cups heavy whipping cream, divided</measure>
    <measure>2 tsp powdered sugar</measure>
    <measure>1 tsp vanilla extract</measure>
    </ingredients>
    <directions>
    Preheat oven to 350&#176;.
    Combine graham cracker crumbs, cocoa and granulated sugar in 9-inch pie plate. Stir in butter until all ingredients are moistened; press onto bottom and up sides of pie plate. Bake for 8 to 10 minutes. Sprinkle 1/2 cup morsels over bottom of hot crust; let stand for 10 minutes or until all morsels are shiny. Spread chocolate over bottom and up sides of crust. Cool to room temperature.

    Microwave 2 cups morsels and 3/4 cup cream in large, microwave-safe bowl on HIGH power for 1 minute; stir. Microwave at additional 10- to 20-second intervals, stirring until smooth. Cool to room temperature.

    Beat remaining cream, sugar and vanilla extract in chilled small mixer bowl until soft peaks form. Fold 2 cups whipped cream into chocolate mixture. Spoon into crust; swirl top. Garnish with remaining whipped cream. Refrigerate until firm.

    Microwave remaining 1/4 cup morsels in heavy-duty plastic bag on high (100%) power for about 30 seconds; knead until smooth. Cut tiny corner from bag; squeeze to drizzle chocolate over pie; let stand a few minutes before serving.
    </directions>
    </recipe>


    <recipe>
    <category>side dish</category>
    <name>Marinated Vegetable Salad</name>
    <ingredients>
    <measure> 3/4 cup Salsa - (Medium)</measure>
    <measure> 1/4 cup lime juice</measure>
    <measure>1/4 cup chopped fresh parsley or cilantro, or 2 tsp dried parsley</measure>
    <measure>2 Tbls olive oil</measure>
    <measure>2 cups chopped tomatoes</measure>
    <measure> 1 can (15 oz.) kidney beans, rinsed and drained</measure>
    <measure> 1 medium ripe avocado, peeled seeded and chopped</measure>
    <measure> 1 cup chopped zucchini</measure>
    <measure> 1 can (4 oz.) diced green chiles</measure>
    <measure>Lettuce leaves</measure>
    </ingredients>
    <directions>
    Combine salsa, lime juice, parsley and olive oil in large bowl. Add tomatoes, kidney beans, avocado, zucchini and chiles. Toss well to coat. Cover; refrigerate for at least 2 hours. Serve over lettuce.
    </directions>
    </recipe>


    <recipe>
    <category>dinner</category>
    <name>Orange Shrimp &#38; Mushroom Pasta</name>
    <ingredients>
    <measure>1-9 oz. package cheese ravioli, prepared according to package directions</measure>
    <measure>1 Tbls olive oil</measure>
    <measure>12 oz. medium raw shrimp, peeled and deveined</measure>
    <measure>1 cup sliced fresh mushrooms</measure>
    <measure>1 package (10 oz.) refrigerated alfredo sauce</measure>
    <measure>3/4 tsp grated orange or tangerine peel</measure>
    </ingredients>
    <directions>
    Heat oil in large, nonstick skillet. Add shrimp; cook, stir occasionally, until pink. Remove from skillet. Add mushrooms; cook, stir occasionally, until soft. Add sauce, orange peel and shrimp; cook, stir frequently, until heated through.

    Place pasta on serving platter; top with sauce. Season with ground black pepper. </directions>
    </recipe>


    <recipe>
    <category>dinner</category>
    <name>Cheese Sauce</name>
    <ingredients>
    <measure>1 (8 oz.) package elbow macaroni</measure>
    <measure>5 Tbls butter</measure>
    <measure>5 Tbls all-purpose flour</measure>
    <measure>1 quart warm milk (110&#176</measure>
    <measure> salt &#176; pepper to taste</measure>
    <measure>1 pinch cayenne pepper</measure>
    <measure>1/4 pound cubed ham</measure>
    <measure>5 oz. cubed cheddar cheese</measure>
    <measure>5 oz. mozzarella cheese, cubed</measure>
    <measure>5 oz. monterey jack cheese, cubed</measure>
    <measure>paprika to taste</measure>
    </ingredients>
    <directions>
    Preheat oven to 350&#176;. Grease a 9 x 13 baking dish. Bring a large pot of lightly salted water to a boil. Add pasta and cook for 8 to 10 minutes or until al dente; drain.
    In medium saucepan, melt butter and stir in flour to make a roux. Cook 1 to 2 minutes, stirring constantly, then whisk in warm milk a little at a time to make a white sauce. Bring to a boil, then reduce heat and simmer. Mix in salt, pepper, and cayenne, and stir frequently until sauce thickens.
    Remove pan from heat and stir in cheddar, mozzarella, jack and ham. Combine pasta with sauce and stir well. Pour into baking dish. Use paprika to make a decorative pattern on top. Bake 45 to 60 minutes, or until top is the desired crispiness. Let rest 20 minutes before serving.
    </directions>
    </recipe>

    <recipe>
    <category>dinner</category>
    <name>Garlic sauce</name>
    <ingredients>
    <measure>1.5 cups white vinegar</measure>
    <measure>1.5 cups sugar</measure>
    <measure>1 tsp chilli paste</measure>
    <measure>.5 tsp salt</measure>
    <measure>2.5 Tbls minced garlic</measure>
    </ingredients>

    <directions>
    Combine all the ingredients in a non-aluminum pan and boil slowly until the mixture is reduced by one half and is the consistency of heavy cream. Can be store for up to 2 months in refrigerator.
    </directions>
    </recipe>

    </recipe_file>




    <?xml version="1.0"?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xslutput method="xml" />

    <xsl:template match="/">

    <html>
    <head>
    <title>style sheet</title>
    </head>

    <body>
    <h2>Stacey's recipe file</h2>

    <table border="1" bordercolor="ff33cc" cellpadding="1" cellspacing="2">
    <tr bgcolor="ffffcc">

    <th>Recipe Name</th>
    <th>Category</th>
    <th>Ingredients</th>
    <th>Directions</th>
    </tr>

    <xsl:for-each select="recipe_file/recipe">

    <tr>
    <td><xsl:value-of select="name"/></td>
    <td><xsl:value-of select="category"/></td>
    <td><xsl:value-of select="ingredients"/><br/></td>
    <td><xsl:value-of select="directions"/></td>
    </tr>
    </xsl:for-each>

    </table>

    </body>
    </html>

    </xsl:template>
    </xsl:stylesheet>

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Stacey,

    The following xsl stylesheet does what you were looking for (I think). Note the following:

    1. I have changed the xslutput method to "html"
    2. I think you may have an error in your xml file - the Lemon Lush recipe has two "ingredients" elements - did you intend this?

    patrick

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xslutput method="html" />
    <xsl:template match="/">

    <html>
    <head>
    <title>style sheet</title>
    </head>
    <body>
    <h2>Stacey's recipe file</h2>
    <table border="1" bordercolor="ff33cc" cellpadding="1" cellspacing="2">
    <tr bgcolor="ffffcc"><th>Recipe Name</th><th>Category</th><th>Ingredients</th><th>Directions</th></tr>
    <xsl:for-each select="recipe_file/recipe">
    <tr>
    <xsl:apply-templates/>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="name">
    <td><xsl:value-of select="preceding-sibling::*"/></td>
    </xsl:template>

    <xsl:template match="category">
    <td><xsl:value-of select="following-sibling::*"/></td>
    </xsl:template>

    <xsl:template match="ingredients">
    <td>
    <xsl:for-each select="measure">
    <xsl:value-of select="."/><br/>
    </xsl:for-each>
    </td>
    </xsl:template>

    <xsl:template match="directions">
    <td><xsl:value-of select="."/></td>
    </xsl:template>

    </xsl:stylesheet>

  • #3
    New Coder
    Join Date
    Mar 2003
    Location
    New Jersey, USA
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thank you Patrick

    Hi Patrick,

    Your xsl worked! I will study the code so I can figure out what you did. As you can see, I'm new to this.

    Thanks again,
    Stacey


  •  

    Posting Permissions

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