I have an xml document which contains a list of items for a bogus online store:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="stock.xsl"?>
<stock>
<item>
<name>Snickers</name>
<price>$1.99</price>
</item>
<item>
<name>Skittles</name>
<price>$2.50</price>
</item>
</stock>
My goal is to make an xsl file that will be able to display this file as a series of text and text boxes that will enable the user to see what the available products are (and at what price) and then input how many they would like to purchase. I am able to produce this, but with one problem: I can't figure out how to give the individual text boxes differing name attributes. Therefore, when the user submits the form, I have no idea which quantity applies to which item. Here is my attempted xsl:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h2 class="center" >Items in Stock</h2>
<br />
<br />
<form method="get" action="cashout.asp" >
<xsl:for-each select="stock/item">
<br />
<br />
<p class="left">
<xsl:value-of select="name" />
Qty:
<input type="text" name="This is what I want to dynamically change based on the <xsl:value-of select="name" value above" />
@
<xsl:value-of select="price" />
</p>
</xsl:for-each>
<br/>
<p class="left">
<input type="submit" name="submit" value="Pay" />
</p>
</form>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
And this is all loaded by an asp file that contains the background and other parts of the page:
Code:
<html>
<head>
<title>Store</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<%
'Displays the contents of the xml database of items in stock using xsl
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("stock.xml"))
'stock.xml is the xml file above
'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("stock.xsl"))
'stock.xsl is the xsl file above
'Transform file
Response.Write(xml.transformNode(xsl))
%>
Edit:
And for further clarification, the html I would like to view after running the asp file is:
Code:
<html>
<head>
<title>Store</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h2 class="center">Items in Stock</h2>
<br>
<br>
<form method="get" action="cashout.asp">
<br>
<br>
<p class="left">
Snickers
Qty:
<input type="text" name="Snickers">
@
$1.99
</p>
<br>
<br>
<p class="left">
Skittles
Qty:
<input type="text" name="Skittles">
@
$2.50
</p>
<br>
<p class="left">
<input type="submit" name="submit" value="Pay">
</p>
</form>
</body>
</html>