|
Subject: RE: [xsl] 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 |
<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] 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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] XSL: Build a dynamic HTML, Andrew Welch | Thread | [xsl] Finding and comparing a paren, Kate Busch Petersen |
| Re: [xsl] XSL: Build a dynamic HTML, Andrew Welch | Date | [xsl] Finding and comparing a paren, Kate Busch Petersen |
| Month |