Welcome to WebmasterWorld Guest from 3.226.251.81

Forum Moderators: open

Message Too Old, No Replies

How to add Listbox in XSLT with XSL?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 25, 2006
posts: 1103
votes: 1


I would like to create the Listbox using XSL. How to do it within XSLT?
3:00 pm on Jan 22, 2009 (gmt 0)

Senior Member from CA 

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

joined:Aug 29, 2003
posts:4061
votes: 0


"Listbox"... do you mean an HTML <select>, with <option>s inside ?
3:13 pm on Jan 22, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 25, 2006
posts:1103
votes: 1


Is there some syntax difference and I use only simple HTML within XSLT file?
3:47 pm on Jan 22, 2009 (gmt 0)

Senior Member from CA 

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

joined:Aug 29, 2003
posts:4061
votes: 0


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>

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 25, 2006
posts: 1103
votes: 1


thank you.

How to add items in this option block?

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

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

Senior Member from CA 

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

joined:Aug 29, 2003
posts:4061
votes: 0


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>
3:20 pm on Feb 3, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 25, 2006
posts: 1103
votes: 1


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.

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

Senior Member from CA 

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

joined:Aug 29, 2003
posts:4061
votes: 0


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.