xsl-list
[Top] [All Lists]

Re: [xsl] Creating a html <select> dropdown menu in XSL, where the attribute of an XML element is the selected value when page loads

2010-01-04 09:27:37
At 2010-01-04 16:10 +0100, Martin Jackson wrote:
Hi,
and thank you!
I'm using xsl1. With the help of Davids tip below I made it work.

> if using xslt1 the faq has various possibilities
>
> such as
>
> <xsl:for-each select="(//*)[position() &lt;= 10]">
> <xsl:variable name="p" select="position()"/>

But new questions arises:

1.This works fine for the days of month, which are never more than 31.
But when I try to build a <select><option> menu with more numbers,
like 50, it only produces a menu with the numbers up to 37. So 37
seems to be some kind of limit. Is there an explanation for this?

You must have only 37 elements in your document. The approach David suggested is a work-around in XSLT 1 since the proper facility is not available to you unless you use XSLT 2. In your original post you mention creating <option> elements, but you don't reveal the basis for enumerating these. Perhaps that will give us a clue in suggesting a way that is not a simple work-around.

For an arbitrary loop, the typical XSLT 1 approach is a recursive template call.

2. Another question is that I also want to make a menu for selecting a
month. I want to use the names of the months, not the numbers. How can
I, with XSL, produce something equivalent to an array filled with the
names of the months?

There is no array concept in XSLT 1 ... in XSLT 2 you can mimic one simply by creating a variable of elements and addressing those. If you want to make a menu, simply write it out ... why do you need an algorithmic approach?

Again, the answer to that would help volunteers understand *why* you think you need an array, rather than just coming up with an analogous approach. In XSLT you have to think differently rather than simply apply traditional approaches with new syntax.

3. And how do I make a menu for years? The "Day of birth" menu starts
from 1 and goes up to 31, but the "Year of birth" menu shouldn't start
from Year 1, but maybe from 1900 and go up to 2010.

Sounds again like a recursive call to me.

Remember that XSLT is a side-effect free functional language. That constrains the programming approaches that can be used, and sometimes stymies programmers who have only learned other "traditional" languages without such constraints.

4. I understand that "(//*)[position() &lt;= 10]" is an XPath
statement, but I don't understand the syntax. Can anyone explain this
a bit?

"(//*)" creates a node set of all elements.

"[position() &lt;= 10]" qualifies only the first 10 of them (all counting in XPath starts at 1).

5. I guess If I understood XPath at a deeper level I would probably be
able to answer a lot of these questions myself. Can anyone recommend a
place where I can find a good explanation of a little more advanced
XPath syntax than the simple expressions used to navigate between
different levels of nodes?

We sell a book that has a free excerpt available on our web site that you can download at no charge in order to decide if the book would be of value to you.

I will soon be announcing upcoming instructor-led hands-on training classes in Europe and the US. Details available on our home page linked in my trailer below.

On January 1 we dropped the price of our 24-hour XSLT training video by 45%, so this might be an alternative for you:

  http://www.CraneSoftwrights.com/training/ptux/ptux-video.htm

Please review the posting guidelines regarding how best to ask questions to help volunteers create answers for you. This will help you get answers more quickly by making it easier for volunteers.

I hope this helps.

. . . . . . . . . . . . Ken

--
UBL and Code List training:      Copenhagen, Denmark 2010-02-08/10
XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
XSLT/XQuery/XPath training:   San Carlos, California 2010-04-26/30
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--