[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XSL: Build a dynamic HTML Select from a single Qu

Subject: RE: XSL: Build a dynamic HTML Select from a single Quantity value
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 7 Aug 2008 17:11:20 +0100
RE:  XSL: Build a dynamic HTML Select from a single  Qu
<xsl:for-each select="1 to Quantity">
  <option value="{.}"><xsl:value-of select="."/></Option>
</xsl:for-each>

This is XSLT 2.0 only.

Michael Kay
http://www.saxonica.com/



> -----Original Message-----
> From: Jimmy D [mailto:webnet02@xxxxxxxxx]
> Sent: 07 August 2008 16:56
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  XSL: Build a dynamic HTML Select from a single
> Quantity value
>
> Hi,
>  
> I've searched the web and archives for the specifics on this
> process but haven't found a good match for what I am trying
> to accomplish. 
>  
> I have the following XML from a third party source I pull
> from the web to populate a web page on my site:
>  
> <?xml version="1.0" encoding="utf-8" ?>
> <Products>
>        <Data Count="2">
>            <Item>
>                <Product>Widget 1</Product>
>                <Quantity>3</Quantity>
>                <Price>10</Price>
>            </Item>
>            <Item>
>                <Product>Widget 2</Product>
>                <Quantity>2</Quantity>
>                <Price>15</Price>
>            </Item>
>        </Data>
> </Products>
>  
> In my style sheet I need to build a HTML drop-down with
> sequential option values equal to the number in <Quantity>
> like so.. Widget 1 <select name="Quantity">
>     <option value="1">1</option>
>     <option value="2">2</option>
>     <option value="3">3</option>
> </select>
>  
> Widget 2
> <select name="Quantity">
>     <option value="1">1</option>
>     <option value="2">2</option>
> </select>
> I am somewhat new to writing style sheets but I am
> experienced in ASP / VBscript where I would handle this with
> a For / Next like:
> <select name="Quantity">
>    <% For count = 1 to Quantity
>             response.write("<option value='" & count & "'>" &
> count & "</option>")
>          Next %> </select>
>  
> However, I haven't figured out how to do this in my style
> sheet.  My XSL looks something like this at the moment:
>  
> <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet
> version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>  <xsl:template match="/">
>    <xsl:choose>
>     <xsl:when test="Products/Data/Item">
>         <table>
>         <xsl:for-each select="Products/Data/Item">
>             <tr>
>                 <td>
>                 <xsl:value-of select="Product" />
>                 </td>
>                 <td>
>                 <xsl:value-of select="Price" />
>                 </td>
>                 <td>Select the number you want to order:
>                     <select name="Quantity">
>                         <!-- Where I'm Stuck -->
>                     </select>
>                 </td>
>               </tr>
>         </xsl:for-each>
>         </table>
>     </xsl:when>
>     <xsl:otherwise>
>     </xsl:otherwise>
>    </xsl:choose>
>  </xsl:template>
> </xsl:stylesheet>
> Thanks for your assistance!
> Jim

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.