homepage Welcome to WebmasterWorld Guest from 54.211.235.255
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

    
How to add Listbox in XSLT with XSL?
toplisek




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

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

 

httpwebwitch




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

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

toplisek




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

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

httpwebwitch




msg:3832296
 3:47 pm on Jan 22, 2009 (gmt 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>

toplisek




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

thank you.

How to add items in this option block?

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

httpwebwitch




msg:3841173
 2:37 pm on Feb 3, 2009 (gmt 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>

toplisek




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

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




msg:3841232
 3:34 pm on Feb 3, 2009 (gmt 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.

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