Chain $ask, $answer and combobox

<oXygen/> general issues.
stutzmann
Posts: 5
Joined: Fri Mar 29, 2019 12:25 am

Chain $ask, $answer and combobox

Post by stutzmann » Mon Apr 01, 2019 1:25 pm

Hello everybody!

(sorry if the question is already dealt with elsewhere, I was not able to find it)

Working on TEI xml files, I am trying to create a function that will prompt the user to give an input and then use the latter to look up for references in an external file. I am not sure if I am concerned with the bug on xpath_eval and ${answer(@id)} (post51917.html)
In this case, the following operations may be chained? I guess one could use insertFragment (e.g. <bibl xmlns="http://www.tei-c.org/ns/1.0">${caret}</bibl>), then ChangeAttribute (and give an input into @sameAs), then base a query based on this intermediary attribute with another ChangeAttribute operation (e.g.

Code: Select all

${ask(
'Choose reference',
combobox,
(
'${xpath_eval(doc('${cfdu}/biblio.xml')//biblStruct[contains(., current-node()/@sameAs)][1]/@xml:id)}':'${xpath_eval(doc('${cfdu}/biblio.xml')//biblStruct[contains(., current-node()/@sameAs)][1]/@xml:id)}';
'${xpath_eval(doc('${cfdu}/biblio.xml')//biblStruct[contains(., current-node()/@sameAs)][2]/@xml:id)}':'${xpath_eval(doc('${cfdu}/biblio.xml')//biblStruct[contains(., current-node()/@sameAs)][2]/@xml:id)}';
'${xpath_eval(doc('${cfdu}/biblio.xml')//biblStruct[contains(., current-node()/@sameAs)][3]/@xml:id)}':'${xpath_eval(doc('${cfdu}/biblio.xml')//biblStruct[contains(., current-node()/@sameAs)][3]/@xml:id)}'
),
'Three first references')}
but I am failing with addressing the current element and deal with the necessary quotes and concatenation of value and labels

Is there a way to use ${answer(@id)} in a single function?

As a comparison, in the associated CSS, it is possible to have
(1) the display of the full reference from the attribute

Code: Select all


bibl[sameAs]{
content:oxy_xpath(
oxy_concat(
"doc('${cfdu}/biblio.xml')//listBibl/biblStruct[@xml:id='", attr(sameAs),"']/normalize-space(string())"
)
);
}
(2) a combobox with a list of all references to choose from:

Code: Select all


bibl:after{
content:"Reference"
oxy_popup(edit, '@sameAs',
values,
oxy_xpath(oxy_concat('string-join(doc("', oxy_url('${cfdu}/biblio.xml'), '")//listBibl/biblStruct/@xml:id, ",")')),
selectionMode, single,
labels,
oxy_xpath(oxy_concat('string-join(doc("', oxy_url('${cfdu}/biblio.xml'), '")//listBibl/biblStruct[@xml:id]/replace(normalize-space(*[1]), ",", "|"), ",")'))
)
}
With the latter, one get the full list, which I would like to reduce by prompting the user to input a string.

Thanks for any help you can offer!
Dominique

sorin_carbunaru
Site Admin
Posts: 259
Joined: Mon May 09, 2016 9:37 am

Re: Chain $ask, $answer and combobox

Post by sorin_carbunaru » Tue Apr 02, 2019 3:46 pm

Dear Dominique,
Working on TEI xml files, I am trying to create a function that will prompt the user to give an input and then use the latter to look up for references in an external file. I am not sure if I am concerned with the bug on xpath_eval and ${answer(@id)} (post51917.html)
According to your description, I would say that the aforementioned bug will indeed affect you. What happens is that xpath_eval functions are evaluated before $ask functions so if your xpath_eval uses an $ask or an $answer it will give incorrect results.
but I am failing with addressing the current element and deal with the necessary quotes and concatenation of value and labels
In this case, the $ask is inside the "value" parameter of an ChangeAttributeOperation, right? To solve the quotes/apostrophe issue, you can use apostrophes on the outside and quotes for the doc function.

Code: Select all

'${xpath_eval(doc("${cfdu}/biblio.xml")//biblStruct[contains(., current-node()/@sameAs)][1]/@xml:id)}'
I don't have a solution for getting the current node inside an XPath expression, though. I will add an issue to offer a custom function for that.
With the latter, one get the full list, which I would like to reduce by prompting the user to input a string.
Perhaps I can offer an alternative. What if you keep using a form control but this time an editable combo box that present just 3 entries, like this:

Code: Select all

bibl:after {
content: "Reference"
oxy_combobox(edit, '@sameAs',
values,
oxy_xpath(oxy_concat('string-join(doc("', oxy_url('${cfdu}/biblio.xml'), '")//listBibl/biblStruct/@xml:id, ",")[position() >= 1 and position() <= 3]')),
editable, true,
labels,
oxy_xpath(oxy_concat('string-join(doc("', oxy_url('${cfdu}/biblio.xml'), '")//listBibl/biblStruct[@xml:id]/replace(normalize-space(*[1]), ",", "|"), ",")[position() >= 1 and position() <= 3]'))
)
}
Best wishes!

stutzmann
Posts: 5
Joined: Fri Mar 29, 2019 12:25 am

Re: Chain $ask, $answer and combobox

Post by stutzmann » Sat Apr 06, 2019 7:00 pm

Dear Sorin,
thank you so much for your answer which has really helped me forward in the last few days.
From your comments on CSS, I have some more question, but I will open an new topic.

For this one, if we try to go around $answer, I wonder if one can integrate $ask within $ask.
Indeed the following works fine, with a combobox generated from an external file with a condition (here, contains a string)

Code: Select all

${ask(
'Choose reference',
combobox,
('${xpath_eval(string-join(doc("${cfdu}/biblio.xml")//listBibl/biblStruct[contains(@xml:id, "1958")]/concat(@xml:id, "':'", normalize-space(string-join(descendant::*, ", "))), "';'"))}'),
'List of references')
}
but apparently one cannot integrate $ask as part of the condition, or not as follows

Code: Select all


${ask(
'Choose reference',
combobox,
('${xpath_eval(string-join(doc("${cfdu}/biblio.xml")//listBibl/biblStruct[contains(., ${ask('search', generic, 'input')})]/concat(@xml:id, "':'", normalize-space(string-join(descendant::*, ", "))), "';'"))}'),
'List of references')
}
Is there here a way forward?
Thanks again, so much!

sorin_carbunaru
Site Admin
Posts: 259
Joined: Mon May 09, 2016 9:37 am

Re: Chain $ask, $answer and combobox

Post by sorin_carbunaru » Mon Apr 08, 2019 5:22 pm

Hi again, Dominique,

Unfortunately there is no way forward on this path... There should be in the future, after we take care of some things, among which is the bug from the post you mentioned in the beginning.

Another approach you could take is to create your own AuthorOperation (see http://ctalau.github.io/userguide/tasks ... HowTo.html), if it sounds appealing to you...

Sorin C.

stutzmann
Posts: 5
Joined: Fri Mar 29, 2019 12:25 am

Re: Chain $ask, $answer and combobox

Post by stutzmann » Fri Apr 12, 2019 10:28 am

Thank you for the answer and for pointing me to a possible solution. I am looking forward to the future improvements. Will you then consider to integrate conditions with other Oxygen editor variables such as ${selection} as well ?

sorin_carbunaru
Site Admin
Posts: 259
Joined: Mon May 09, 2016 9:37 am

Re: Chain $ask, $answer and combobox

Post by sorin_carbunaru » Fri Apr 12, 2019 11:51 am

Yes, we want so support all kinds of meaningful combinations of editor variables.

sorin_carbunaru
Site Admin
Posts: 259
Joined: Mon May 09, 2016 9:37 am

Re: Chain $ask, $answer and combobox

Post by sorin_carbunaru » Thu May 23, 2019 2:42 pm

Hello,

Just wanted to announce that oXygen 21.1 has just been released a few hours ago, and it has an improved way of dealing with editor variables.
Best wishes,
Sorin Carbunaru
oXygen XML

Post Reply