Hi Mike,
The attribute has to be within the option tag as follows:
...
<option value="1" {
if ($flag) then attribute selected { 1 } else ()
}>Select one</option>
...
However, this also fails. I will try writing a function to create the
option element - that's worth a try!
Thanks,
Tim
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Michael
Blakeley
Sent: Tuesday, November 11, 2008 3:20 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] Embedding the selected attribute in
anHTML select list with xquery
Tim,
This looks like a good time to use a computed constructor.
...
<option value="1">{
if ($flag) then attribute selected { 1 } else ()
}Select one</option>
...
You could also write a function to create the option element with or
without the attribute, but I think the computed constructor is cleaner.
-- Mike
Tim Meagher wrote:
> I am trying to programmatically embed the "selected" attribute in a select
> list using xquery but am running into problems. Basically I am writing a
> form that calls itself and trying to set the select value to that of the
> previous value. What is shown in the following code does not show the
logic
> for obtaining the request field, but it does show the problem with trying
to
> set the selected attribute programmatically.
>
> Here is the code that fails (which you can run in CQ to verify this):
>
> xquery version "1.0-ml";
> let $selected := if (true()) then "selected=""selected""" else ""
> return
> <html xmlns="http://www.w3.org/1999/xhtml">
> <body>
> <h3>RefXPress Phase 1 Book Titles</h3>
> <form name="test" action="analysis-and-statistics.xqy" method="post">
> Book Title Sort Order:
> <select name="order">
> <option value="one" {$selected}>Select one</option>
> <option value="two">Select two</option>
> </select>
> </form>
> </body>
> </html>
>
>
> Apparently it doesn't like adding an attribute unless the attribute is
> hard-coded and the value is optional. So changing the selected attribute
to
> a hard-coded value as follows will generate the HTML page without error.
> Note that in XHTML, the "selected" attribute must also have a value, but
it
> is merely the presence of the attribute and not the value that causes the
> select list option to be selected when displaying the form.
>
>
> xquery version "1.0-ml";
> let $sel:= """selected"""
> return
> <html xmlns="http://www.w3.org/1999/xhtml">
> <body>
> <h3>RefXPress Phase 1 Book Titles</h3>
> <form name="test" action="analysis-and-statistics.xqy" method="post">
> Book Title Sort Order:
> <select name="order">
> <option value="one" selected={$sel}>Select one</option>
> <option value="two">Select two</option>
> </select>
> </form>
> </body>
> </html>
>
>
> The only problem with that is that the selected attribute is hard-coded,
> therefore the item will always be selected. The same problem exists
trying
> to programmatically add the "checked" attribute to a list of radio
buttons.
>
> I would like to be able to programmatically set the attribute without
having
> to use javascript to iterate through the select list to set the
appropriate
> selected index. Perhaps there are some other ways to solve this. Any
help
> would be much appreciated! If this cannot be done with xquery, does
anyone
> have an example of doing this in javascript within an xquery page?
>
> Thank you!
>
> Tim Meagher
>
>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general