Jump to content

SimonLee

Members
  • Posts

    1
  • Joined

  • Last visited

SimonLee's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Do anyone know what is wrong and what I can do to fix this? Thanks. <?xml version="1.0" encoding="UTF-8" ?> <?xml-stylesheet type="text/xsl" href="cars.xsl"?> <cars> <car id="001"> <name>Lexus</name> <qty>5</qty> <price>12000</price> </car> <car id="002"> <name>Honda</name> <qty>14</qty> <price>22299</price> </car> <car id="003"> <name>BMW</name> <qty>23</qty> <price>3299</price> </car> </cars> <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" version="4.0" /> <!-- start of root template --> <xsl:template match="/"> <html> <head> <title>Car Sales</title> </head> <body> <table border="1" cellpadding="5" cellspacing="5"> <tr> <!-- row 1 --> <th colspan="2">Cars List</th> </tr> <tr> <!-- row 2 --> <th>Cars:</th> <td><xsl:value-of select="count(//car)"/></td> </tr> <tr> <!-- row 3 --> <th>Quantity:</th> <td><xsl:value-of select="sum(//qty)"/></td> </tr> <tr> <!-- row 4 --> <th>Total Sale:</th> <td> <xsl:call-template name="calctotalsales"/> </td> </tr> </table> </body> </html> </xsl:template> <!-- end of root template --> <!-- start of calctotalsales template --> <xsl:template name="calctotalsales"> <xsl:param name="list"/> <xsl:param name="total" select="0"/> <!-- calculate the total car cost --> <xsl:choose> <xsl:when test="$list"> <!-- calculate the first car sales --> <xsl:variable name="firstsales" select="$list[1]/cars/car/qty * $list[1]/cars/car/price" /> <!-- call the totalcost template --> <xsl:call-template name="calctotalsales"> <xsl:with-param name="list" select="$list[position() > 1]" /> <xsl:with-param name="total" select="$firstsales + $total" /> </xsl:call-template> </xsl:when> <!-- list of records finished, time to display the total cost --> <xsl:otherwise> <xsl:value-of select="format-number($total, '$#,#00.00')" /> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- end of calctotalsales template --> </xsl:stylesheet>
×
×
  • Create New...