I am having issues with an assignment in my XML class. We have been assigned to create an XSL document and format some pre-existing XML files. For some reason I'm not able to view my XML file and I think it has to do with an error in the XSL, but I'm not sure.
Here's the XSL File (flowers.xsl)
<?xml version="1.0" encoding="UTF-8" ?>
<!--
New Perspectives on XML
Tutorial 8
Case Problem 2
WebFlowers XSLT Style Sheet
Filename: flowers.xsl
Supporting Files: customers.xml, flowers.css, items.xml
-->
<xsl:stylesheet version='1.0' xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable
name="items"
select="items.xml">
</xsl:variable>
<xsl:variable
name="customers"
select="customers.xml">
</xsl:variable>
<key id=ID name=itemID>
</key>
<key id=ID name=custID>
</key>
<key id=date name=date>
</key>
<xsl:template match="/">
<html>
<head>
<title>Flower Orders</title>
<link href="flowers.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Flower Orders</h1>
<table>
<tr>
<th>Date</th>
<th>Customer</th>
<th>Item</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>
<xsl:key name="order-by-date" match="date" use="key(date)" />
<xsl:template match="order">
<xsl:for-each select="date[count(. | key('order-by-date', date)[1]) = 1]">
<xsl:sort select="date" />
</xsl:for-each>
</xsl:template>
<tr>
<td colspan="4" class="grand">Grand Total</td>
<td class="grand"> sum(qty)</td>
<td class="grand">
<xsl:template match="totalCost" list="key(order)"
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="order">
<xsl:variable
name="cID"
select="customer">
</xsl:variable>
<xsl:variable
name="iID"
select="item">
</xsl:variable>
<xsl:variable
name="qtyValue"
select="qty">
</xsl:variable>
<tr>
<!-- Display order date -->
<xsl:if test="position() == 1">
<td rowspan="rows" class="date">
date
rows=count(<xsl:value-of select="current()"/>)
</td>
</xsl:if>
<!-- Display customer information -->
<xsl:for-each select="customers">
<td>
<xsl:key name="order-by-name" match="key(custID)\name" use="cID" /><br/>
<xsl:key name="order-by-city" match="key(custID)\city" use="cID" /> <br/>,
<xsl:key name="order-by-state" match="key(custID)\state" use="cID" />   
<xsl:key name="order-by-zip" match="key(custID)\zip" use="cID" />
</td>
</xsl:for-each>
<!-- Display item name and price-->
<xsl:for-each select="items">
<td>
<xsl:key name="order-by-name" match="key(itemID)\name" use="iID" />
</td>
<td class="num">
<xsl:key name="order-by-price" match="key(itemID)\price" use="iID" />
</td>
</xsl:for-each>
<!-- Display item quantity -->
<td class="num"><xsl:value-of select="@qty" /></td>
<!-- Display cost of items ordered -->
<xsl:for-each select="items">
<td class="num">
item cost
</td>
</xsl:for-each>
</tr>
<!-- Display subtotals -->
<xsl:if test="position()=last()">
<tr><td colspan="5"><hr /></td></tr>
<tr>
<td colspan="3" class="sub">Subtotal</td>
<td class="sub">sum(current(key(date)), current(key(qty)))</td>
<td class="sub">
<xsl:template match="node(key(date))" mode="rows">
</xsl:template>
</td>
</tr>
<tr><td colspan="6"><hr /></td></tr>
</xsl:if>
</xsl:template>
<xsl:template match="/">
<xsl:param name="list"/>
<xsl:param name="total" select="0"/>
<xsl:choose>
<xsl:when test="$list == NULL">
<xsl:variable
name="first"
select="list">
</xsl:variable>
<xsl:variable
name="iID"
select="item">
</xsl:variable>
<xsl:variable
name="itemQty"
select="qty">
</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='format-number (total, "$#,#00.00)' />
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="items">
<xsl:variable
name="itemPrice"
select="key(itemID, iID)">
</xsl:variable>
</xsl:for-each>
<xsl:call-template name="totalCost">
select= ($itemQty * $itemPrice + $total)
</xsl:call-template>
</xsl:stylesheet>
And here's one of the XML files that this stylesheet is attached to:
<?xml version="1.0" encoding="UTF-8" ?>
<!--
New Perspectives on XML
Tutorial 8
Case Problem 2
WebFlowers Items Data
Filename: items.xml
Supporting Files:
-->
<?xml-stylesheet type="text/xsl" href="flowers.xsl"?>
<items>
<item id="F101">
<name>Large Flower Vase Arrangement</name>
<price>74.99</price>
</item>
<item id="F102">
<name>Flowers Galore: Orchids and Roses</name>
<price>89.99</price>
</item>
<item id="F103">
<name>Bear with Dozen Roses</name>
<price>82.99</price>
</item>
<item id="F104">
<name>Medium Ivy Flower Bowl</name>
<price>49.99</price>
</item>
<item id="F105">
<name>Flower Bowl</name>
<price>54.99</price>
</item>
<item id="F106">
<name>One Dozen Red Roses</name>
<price>64.99</price>
</item>
<item id="F107">
<name>One Dozen White Roses</name>
<price>62.99</price>
</item>
<item id="F108">
<name>One Dozen Pink Roses</name>
<price>62.99</price>
</item>
<item id="F109">
<name>Fragrant Garden Basket</name>
<price>49.99</price>
</item>
<item id="F110">
<name>Classic Vase</name>
<price>64.99</price>
</item>
<item id="F111">
<name>White Flower Elegance</name>
<price>84.99</price>
</item>
<item id="F112">
<name>Flowers to Go</name>
<price>44.99</price>
</item>
<item id="F113">
<name>Bright Autumn Flowers</name>
<price>49.99</price>
</item>
<item id="F114">
<name>Pedestal Bowl</name>
<price>49.99</price>
</item>
<item id="F115">
<name>Summer Vase</name>
<price>69.99</price>
</item>
<item id="F116">
<name>Dizzy with Daisies</name>
<price>44.99</price>
</item>
<item id="F117">
<name>Fragrant Pink Lillies</name>
<price>72.99</price>
</item>
<item id="F118">
<name>Medley Basket</name>
<price>54.99</price>
</item>
<item id="F119">
<name>Romantic Vase</name>
<price>67.99</price>
</item>
<item id="F120">
<name>Spring Fling Flowers</name>
<price>59.99</price>
</item>
<item id="F121">
<name>Fragrant Lillies</name>
<price>74.99</price>
</item>
<item id="F122">
<name>Spring Flower Basket</name>
<price>54.99</price>
</item>
<item id="F123">
<name>Enchanted Roses</name>
<price>59.99</price>
</item>
<item id="F124">
<name>Large Flower Vase Arrangement</name>
<price>159.99</price>
</item>
<item id="F125">
<name>Spring Blooms</name>
<price>54.99</price>
</item>
<item id="F126">
<name>White Bear Bouquet</name>
<price>49.99</price>
</item>
<item id="F127">
<name>Golden Basket</name>
<price>69.99</price>
</item>
<item id="F128">
<name>Regal Iris Vase</name>
<price>57.99</price>
</item>
<item id="F129">
<name>Flowers of Europe</name>
<price>69.99</price>
</item>
<item id="F130">
<name>Fragrant Blooms</name>
<price>59.99</price>
</item>
<item id="F131">
<name>Pretty in Pink</name>
<price>49.99</price>
</item>
<item id="F132">
<name>Spray of Roses</name>
<price>69.99</price>
</item>
<item id="F133">
<name>Yellow Sunflowers</name>
<price>59.99</price>
</item>
<item id="F134">
<name>Bright Spring Vase</name>
<price>43.99</price>
</item>
<item id="F135">
<name>Yellow Daisy Vase</name>
<price>49.99</price>
</item>
<item id="F136">
<name>Spring Compote</name>
<price>109.99</price>
</item>
<item id="F137">
<name>Country Garden Basket</name>
<price>59.99</price>
</item>
<item id="F138">
<name>Sunflower Basket</name>
<price>56.99</price>
</item>
<item id="F139">
<name>Medium Ginger Jar</name>
<price>44.99</price>
</item>
<item id="F140">
<name>Pleasant Basket</name>
<price>99.99</price>
</item>
</items>
Any help would really be appreciated, be it references to the correct way to do this or just pointing out errors. Thank you in advance!
Run your XSLT/XML through a validator to get more information on this but from my initial run, the first issue is on the
keytag. Ensure you enclose the values of your attributes in quotes as shown below:XML validator: http://bit.ly/1nl0BFa