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 June 22nd, 2007, 05:59 AM
Registered User
 
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Named template being called, to no effect (newb)

I'm a total XSLT newbie, and I'm having trouble understanding why this XSL transformation won't run. I have traced the execution in VS 2005 (great debugger, btw) and apparently the template isn't called.

The XSL:
Code:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <head>
                <title>xsl lab</title>
            </head>
            <body>
                Juicers
                <br/>
                <br/>
                <xsl:variable name="sum" select="sum(/juicers/juicer/cost)"/>
                <xsl:variable name="count" select="count(/juicers/juicer)"/>
                <xsl:variable name="avg" select="$sum div $count"/>
                Total number of juicers: <xsl:value-of select="$count"/> <br/>
                Cost of all juicers: <xsl:value-of select="format-number($sum,'#.00')"/> <br/>
                The average cost of the juicers: <xsl:value-of select="format-number($avg,'$#.00')"/> <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <table border="1" width="30%">
                    <th>
                        Juicer
                    </th>
                    <th>
                        Cost
                    </th>
                    <th>
                        New Cost
                    </th>
                    <xsl:variable name="adjustments"
                            select="document('priceAdjuster2.xml')"/>
                    <xsl:for-each select="/juicers/juicer">
                        <tr>
                            <td>
                                <xsl:value-of select="name"/>
                            </td>
                            <td>
                                <xsl:value-of select="cost"/>
                            </td>
                            <td>
                                <xsl:variable name="action" select="$adjustments/priceAdjustment/adjustment/@action"/>
                                <xsl:choose>
                                    <xsl:when test="$action='no change'">
                                        <xsl:value-of select="cost"/>
                                    </xsl:when>
                                    <xsl:when test="$action='increase'">
                                        <xsl:variable name="result">
                                            <xsl:call-template name="applyCostIncrease">
                                                <xsl:with-param name="originalCost" select="./cost"/>
                                                <xsl:with-param name="increase" select="$adjustments/priceAdjustment/adjustment/sizeIncrease"/>
                                            </xsl:call-template>
                                        </xsl:variable>
                                        <xsl:value-of select="result"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        no idea [<xsl:value-of select="$action"/>]
                                    </xsl:otherwise>
                                </xsl:choose>
                            </td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>

    <xsl:template name="applyCostIncrease" match="/">
        <xsl:param name="originalCost"/>
        <xsl:param name="increase"/>
        <xsl:value-of select="$originalCost + $increase"/>
    </xsl:template>

</xsl:stylesheet>
The XML:
Code:
<?xml version="1.0"?>
<!DOCTYPE juicers SYSTEM "juicers.dtd">
<juicers>
      <juicer id="mighty-oj" electric="false" type="press">
          <name>OJ Home Juicer</name>
          <image>images\mighty_oj.gif</image>
          <description>There&apos;s just no substitute for a properly squeezed orange in the morning. So delicate and refreshing. The finest hotels use mechanical juicers of this type for their most discriminating guests. This is the largest selling juicer of its kind. It&apos;s a beautiful little all-metal piece in baked enamel and polished chrome; it even won the Frankfurt Fair Award for its design. Uses no electricity and produces no non-recyclable waste as do frozen juices.</description>
          <warranty>lifetime warranty</warranty>
          <weight></weight>
          <cost currency="USD">41.95</cost>
          <retailer>http://www.thewhitewhale.com/oj.htm</retailer>
      </juicer>
      <juicer id="champion" electric="true" type="gear">
          <name>Champion Juicer</name>
          <image>images\champion.gif</image>
          <description>The Champion Juicer is the answer to every juicing problem. Because it operates on the mastication process principle, the Champion chews the fibers and breaks up the cells of vegetables and fruits. 
This give you more fiber, enzymes, vitamins and trace minerals. The juice will be a darker, richer color, with a sweeter, richer more full-bodied flavor.
</description>
          <warranty></warranty>
          <weight></weight>
          <cost currency="USD">239.00</cost>
          <retailer>http://www.grainsandgreens.com/juicerparts.html</retailer>
      </juicer>
      <juicer id="green-power" electric="true" type="gear">
          <name>Green Power Gold Juice Extractor</name>
          <image>images\greenPower.jpg</image>
          <description>You are not What You Eat, But What you Absorb.  The rate of absorption of juice has never been considered a factor in comparing juicers. With the introduction of Green Power&apos;s magnetic Twin Gear press, this has now changed. Experiments conducted by the Green Power Co. Research and Development Dept. show the rate of absorption of green juice using dual gear extraction is up to five times greater than using centrifugal extraction.</description>
          <warranty></warranty>
          <weight></weight>
          <cost currency="USD">459.99</cost>
          <retailer>http://www.discountjuicers.com/greencomplete.html</retailer>
      </juicer>
      <juicer id="juiceman-jr" electric="true" type="centrifugal">
          <name>Juiceman Jr.</name>
          <image>images\juiceman.jpg</image>
          <description>The Juiceman Jr. juicer is the little brother to the Juiceman II juicer that is seen on television. The Juiceman Jr. is a pulp ejection juicer that allows you to juice continuously without having to stop and clean the machine.
Made popular by Jay Kordich, the Juiceman series of juicers have been a popular addition to millions of households all across this nation. This machine comes ready to use out of the box</description>
          <warranty>1 yr. Limited Warranty </warranty>
          <weight>10</weight>
          <cost currency="USD">82.00</cost>
          <retailer>http://www.juicebars.com/juicers/jm1.htm</retailer>
      </juicer>
      <juicer id="omega" electric="true" type="centrifugal">
          <name>Omega Juicer</name>
          <image>images\omega.jpg</image>
          <description>This heavy-duty, American-made juicer has a powerful GE motor that spins at 3,600 rpm to extract 20% - 30% more juice than pulp ejector models (according to independent laboratory tests). Large capaciy bowl hold a ful 1-2 quarts of fruits or vegetables - compared to just one pint for many brands. Easy-cleaning design with lift out disposable filter.</description>
          <warranty></warranty>
          <weight></weight>
          <cost currency="USD">234.00</cost>
          <cost currency="CND">359.50</cost>
          <retailer>http://www.boschcanada.com/omega.htm</retailer>
      </juicer>
      <juicer id="wheateena" electric="true" type="gear">
          <name>Wheateena Wheatgrass Juicer</name>
          <image>images\wheateena.jpg</image>
          <description>Wheatgrass juice contains 70% "crude" chlorophyll. Chlorophyll by definition being the green pigment in plants. It is considered the "blood" of plants, due to the similarity to our blood in molecular structure. This juicer extracts the juice out of the blades of wheatgrass. Normal fruit and vegetable juicers will not juice wheatgrass</description>
          <warranty>Motor Guarantee: For Home Use: one (1) year. For Commercial Use: six (6) months.</warranty>
          <weight>46</weight>
          <cost currency="USD">639.99</cost>
          <retailer>http://www.rawfoods.com/marketplace/heavyduty.html</retailer>
      </juicer>
</juicers>
Any idea why the template is not executed?

 
Old June 22nd, 2007, 06:22 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Change

<xsl:value-of select="result"/>

to

<xsl:value-of select="$result"/>

Your stylesheet doesn't use the $result variable, so the processor hasn't bothered to evaluate it.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 22nd, 2007, 07:40 AM
Registered User
 
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help! :D





Similar Threads
Thread Thread Starter Forum Replies Last Post
I'm a newb.... I think I'm doing something wrong.. aaronmuslim XSLT 10 March 18th, 2008 01:02 PM
NEWB HERE Romaunt V. C# 8 August 16th, 2007 11:52 AM
Newb question zenobr BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 November 15th, 2006 10:19 PM
XSLT Newb. TimJR88 XSLT 1 November 21st, 2005 03:14 PM
Help for named template wu4 XSLT 2 October 18th, 2005 10:09 AM





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