homepage Welcome to WebmasterWorld Guest from 184.73.40.21
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
Populating a Drop Down given a number attribute
rk330

5+ Year Member



 
Msg#: 3198590 posted 1:12 am on Dec 24, 2006 (gmt 0)

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="http://www.w3.org/1999/XSL/Transform"
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">&amp;nbsp;</xsl:text><xsl:value-of select="@SeatSection"/><xsl:text disable-output-escaping="yes">&amp;nbsp;&amp;nbsp;</xsl:text><b>Row:</b><xsl:text disable-output-escaping="yes">&amp;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">&amp;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

 

macrost

10+ Year Member



 
Msg#: 3198590 posted 3:39 am on Dec 25, 2006 (gmt 0)

Is your XSL even transforming? I just tried a quick test in my IDE and the XSL wouldn't even transform. Are you doing it server side?

macrost

10+ Year Member



 
Msg#: 3198590 posted 4:28 am on Dec 25, 2006 (gmt 0)

Ok, here you go, you need a recursive template to accomplish what you are needing.
-------XML----------

<?xml version="1.0" encoding="UTF-8"?>
<tickets>
<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" />
<row TicketID="17633051" Available="4" 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" />
<row TicketID="17633052" Available="5" 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" />
<row TicketID="17633053" Available="2" 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" />
</tickets>

-----------XSL--------------

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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">&amp;nbsp;</xsl:text>
<xsl:value-of select="@SeatSection"/>
<xsl:text disable-output-escaping="yes">&amp;nbsp;&amp;nbsp;</xsl:text>
<b>Row:</b>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:value-of select="@SeatRow"/>
</td>
<td>$<xsl:value-of select="@TicketPrice"/> each</td>
<td>
<select name="test">
<xsl:call-template name="loop">
<xsl:with-param name="loop-variable">1</xsl:with-param>
<xsl:with-param name="loop-limit" select="@Available"></xsl:with-param>
</xsl:call-template>

</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">&amp;nbsp;</xsl:text>
<xsl:value-of select="@SeatDescription"/>
</font>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name="loop">
<xsl:param name="loop-variable"/>
<xsl:param name="loop-increment">1</xsl:param>
<xsl:param name="loop-limit"/>
<xsl:param name="loop-variable-next">
<xsl:value-of select="$loop-variable + $loop-increment"/>
</xsl:param>

<option><xsl:value-of select="$loop-variable"/></option>

<xsl:choose>
<xsl:when test="$loop-variable-next &lt;= $loop-limit">
<xsl:call-template name="loop">
<xsl:with-param name="loop-variable">
<xsl:value-of select="$loop-variable-next"/>
</xsl:with-param>
<xsl:with-param name="loop-increment">
<xsl:value-of select="$loop-increment"/>
</xsl:with-param>
<xsl:with-param name="loop-limit">
<xsl:value-of select="$loop-limit"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>


rk330

5+ Year Member



 
Msg#: 3198590 posted 3:43 am on Dec 27, 2006 (gmt 0)

Greetings macrost, Thank you very much for the reply. I will give it a shot first thing in the morning and let you know how it turns out. I had a feeling that a recursive template was my only option, I just couldn't get it all together without xsl errors.

Again, thanks and I will let you know how it turns out.

_ramzy

rk330

5+ Year Member



 
Msg#: 3198590 posted 11:03 pm on Dec 27, 2006 (gmt 0)

Works great! Thanks again for the help

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved