Hi Tim,
For the sake of completeness, there are basically two ways of constructing
attribute nodes:
Literal:
myatt="myvalue"
example: <myelem myatt="myvalue" />
Computed:
attribute myatt {"myvalue"} or attribute {"myatt"} {"myvalue"}
example:
<myelem>
{ attribute myatt {"myvalue"} }
</myelem>
The literal construction must be applied to start tags, the computed
construction must be performed between the tags, BUT must be inserted before
any other type of node, e.g:
<myelem>
{ attribute myatt {"myvalue"} }
mytext
<mychildelem/>
moretext
</myelem>
Note, this can also be written as:
<myelem> {
attribute myatt {"myvalue"},
"mytext",
<mychildelem/>,
"moretext"
} </myelem>
(Mind the commas, the quotes, and note that the whitespace in the resulting
element is not exactly the same.)
Next to this, there is the phenomenon called 'attribute value templates'. These
always occur within attribute values:
myatt="blabla{string(someelem/@someatt)}blabla"
With all the subtleties in those braces, I am not surprised to see you get
confused. Hope my explanation helps a bit.
Kind regards,
Geert
> Hi Mike,
>
> My apologies. Your syntax DID fix the problem. I was
> mistaken in assuming that the attribute had to be constructed
> inside the option tag.
>
> Tim
>
>
Drs. G.P.H. Josten
Consultant
http://www.daidalos.nl/
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665 JZ Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
http://www.daidalos.nl/
KvK 27164984
De informatie - verzonden in of met dit emailbericht - is afkomstig van
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit
bericht kunnen geen rechten worden ontleend.
> From: Tim Meagher [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, November 11, 2008 3:41 PM
> To: 'General Mark Logic Developer Discussion'
> Subject: RE: [MarkLogic Dev General] Embedding the selected
> attribute in anHTML select list with xquery
>
> 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
>
>
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general