Jinntec / Fore

Fore - declarative user interfaces in plain HTML
MIT License
82 stars 11 forks source link

Unable to get attribute value using the <fx-output> element #287

Open daliboris opened 1 month ago

daliboris commented 1 month ago

I'm trying to get the value of the attribute using the <fx-output> element.

Sample input data:

<item xml:id="rochotius-comoedia.comm.000005">
 <app from="#rochotius-comoedia.comm.000005.start" n="5">
  <note>
   <cit>
    <quote type="paraphrase" subtype="equal">Senex </quote>
   </cit>
   <cit>
    <quote type="paraphrase" subtype="equal"> Senex</quote>
   </cit>
  </note>
 </app>
</item>

Each of the the following statement returns undefined in the output (HTML page):

<fx-output ref="app//cit" value="quote/@type"></fx-output>
<fx-output ref="app//quote" value="@type"></fx-output>
<fx-output ref="app//quote" value="./@type"></fx-output>

Two following approaches return the value, but the result contains only one item while the source contains two elements with the @type attribute.

<fx-output ref="app//quote/@type"></fx-output>
<fx-output ref="for $quote in app//quote return $quote/@type"></fx-output>

The <fx-repeat> element with template expressions returns the expected result: two values of the @type attribute:

<fx-repeat ref="app/note/cit/quote">
  <template>
   <span>{./@type}</span>
  </template>
</fx-repeat>

Is it possible to use XPath for retrieving attribute value of the element from within @value attribute of the <fx-output> element?

I know that for repeated elements using <fx-repeat> element makes sense, but even if the source <note> element contains only one <cit>/<quote> sequence the <fx-output ref="app//quote" value="./@type" /> or <fx-output ref="app/note/cit/quote" value="./@type" /> returns undefined.

JoernT commented 1 month ago

@daliboris It's not 100% clear to me what you're trying to achieve/expecting - output both occurrences of @type?

We'll have a look at this.

DrRataplan commented 1 month ago

I think both occurrences here might make sense. But on the other hand, for a control you definitely don't want to edit both instances at once, right?

What does the xforms spec say? That's usually a good guideline

On Mon, 16 Sept 2024, 13:24 Joern Turner, @.***> wrote:

@daliboris https://github.com/daliboris It's not 100% clear to me what you're trying to achieve/expecting - output both occurrences of @type?

We'll have a look at this.

— Reply to this email directly, view it on GitHub https://github.com/Jinntec/Fore/issues/287#issuecomment-2352649076, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGKEJFTNDQFJPMBICER57LZW25YRAVCNFSM6AAAAABOGG6K5OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJSGY2DSMBXGY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

JoernT commented 1 month ago

The XForms spec says that controls (including output) use 'single item binding':

When a binding is defined as a Single Item Binding then the First-item rule is applied: if a binding selects a sequence of size greater than 1, the first item in the sequence is used.

Further there not a single example using both ref and value at the same time though i also don't see it to be explicitly denied.

Though we don't necessarily need to follow the spec in all cases i guess it makes sense here to restrict controls to 'single item bindings' - the only exception (of course) is the repeat element.

Therefore if you want to output multiple nodes/values you'll have to use fx-repeat or maybe have your own custom function for that.

JoernT commented 1 month ago

@daliboris could you please give more context about your use case? If we know what you're trying to achieve we can help to work out a solution but we need to clarify if this is really an issue or otherwise needs addressing/working out a solution.

JoernT commented 1 month ago

I'll leave the ticket open for another week or so but i don't see an issue here though i might be missing something. If you can please elaborate on the problem? Is it still a problem? If so, we can work out a proper solution if we have a concrete use case to fulfill.