Populating a Drop Down given a number attribute in XSL

webmasterbeta

New Member
Hello,

I have been struggling with this for the past few days and need your help. I have xml data that looks something like this..

<row TicketID="17633050" Available="8" EventDate="2006-12-27T19:30:00" SeatSection="51" SeatRow="M" SeatFrom="*" SeatThru="*" SeatDescription="FEDEX 1 WEEK PRIOR TO EVENT!" TicketPrice="175" BrokerPrice="175" BrokerID="0" />


Using MSXML 4.0, my XSL file currently loops through each //row node and collects the data for each attribute. I have only one problem, the @Available attribute requires me to display a drop down on the html side as a "quantity". Because the xml only provides a number, I need to create a loop that creates an <option></option> for each @Available -1 except for a value that would leave 1. ( that may sound confusing but here is an example)

Example: If the xml value is 8. My drop down list would have to include 8,6,5,4,3,2,1. I cannot have a value of 7 as an option since that leaves only 1 qty available for purchase when 7 is selected.

My current xsl file looks something like this...

<!--#include file='includes/misc_funcs.asp'-->
<xsl:stylesheet version="1.0"
xmlns:xsl="(URL address blocked: See forum rules)"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:dt="urn:schemas-microsoft-com:datatypes"
xmlns:vbs="urn:schemas-sqlxml-org:vbs">

<xsl:template match="/">
<xsl:call-template name="tickets"/>
</xsl:template>

<xsl:template name="tickets">
<table cellspacing="0" cellpadding="2">
<tr><th width="200" align="left">Seat Location</th><th width="100" align="left">Price</th><th width="100" align="left">Quantity</th><th width="80" align="center">Buy</th></tr>
<xsl:for-each select="//row">
<xsl:sort select="@TicketPrice" order="ascending" data-type="number"/>
<xsl:variable name="qty" select="@Available"/>
<tr>
<xsl:if test="(position() mod 2 = 1)">
<xsl:attribute name = "bgcolor">#f4f4f4</xsl:attribute>
</xsl:if>
<td><b>Sec:</b><xsl:text disable-output-escaping="yes">&nbsp;</xsl:text><xsl:value-of select="@SeatSection"/><xsl:text disable-output-escaping="yes">&nbsp;&nbsp;</xsl:text><b>Row:</b><xsl:text disable-output-escaping="yes">&nbsp;</xsl:text><xsl:value-of select="@SeatRow"/></td>
<td>$<xsl:value-of select="@TicketPrice"/> each</td>
<td><select><option><xsl:value-of select="@Available"/></option>
<option><xsl:value-of select="for $qty in (1 to $qty) return $qty - 1"/></option>
</select> of <xsl:value-of select="@Available"/></td>
<td align="center" valign="middle"><button name="buy">Buy</button></td>
</tr>
<tr>
<xsl:if test="(position() mod 2 = 1)">
<xsl:attribute name = "bgcolor">#f4f4f4</xsl:attribute>
</xsl:if>
<td colspan="5"><font size="2"><b>Notes:</b><xsl:text disable-output-escaping="yes">&nbsp;</xsl:text><xsl:value-of select="@SeatDescription"/></font></td></tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

Any help would be greatly appreciated as I am stuck and cannot proceed.

Thanks in advance!
_ramzy
 
Back
Top