Welcome to WebmasterWorld Guest from 54.226.32.234

Forum Moderators: httpwebwitch

Message Too Old, No Replies

How to add Listbox in XSLT with XSL?

     

toplisek

12:31 pm on Jan 21, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I would like to create the Listbox using XSL. How to do it within XSLT?

httpwebwitch

3:00 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



"Listbox"... do you mean an HTML <select>, with <option>s inside ?

toplisek

3:13 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Is there some syntax difference and I use only simple HTML within XSLT file?

httpwebwitch

3:47 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



you do put plain HTML right into your XSLT.

consider this sample

<select>
<xsl:for-each select="/item">
<option><xsl:value-of select="@name"/></option>
</xsl:for-each>
</select>

toplisek

12:49 pm on Feb 3, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



thank you.

How to add items in this option block?

Like www.google.com and www.mastercard.com in correct way?

httpwebwitch

2:37 pm on Feb 3, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



see the description of <option> [w3schools.com] at W3Schools

I usually state the value of an option explicitly, like this:

<option value="12345">Ford Prefect</option>

in XSLT, this would turn into:

<select> 
<xsl:for-each select="/item">
<option>
<xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute>
<xsl:value-of select="@name"/>
</option>
</xsl:for-each>
</select>

toplisek

3:20 pm on Feb 3, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



So, you mean in XSLT:

<select>
<xsl:for-each select="/item">
<option value="12345">Ford Prefect</option>
<option value="12345">Mercedes best</option>
<option value="12345">Fiat Perfect</option>
<xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute>
<xsl:value-of select="@name"/>
</option>
</xsl:for-each>
</select>

I have predefined values of items from server.

httpwebwitch

3:34 pm on Feb 3, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



10 try it and see if it produces the results you desire.
20 If it doesn't, GOTO 10

debugging is an iterative process. The best way to learn the syntax of a language, whether it's HTML or XSLT, is to read, experiment, and play with it. I'd suggest getting an XSLT debugger which lets you edit XSLT and see the results immediately - there are several good ones out there with trial versions you can play with before purchasing.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month