Page 1 of 1

dynamic link construction for authors

Posted: Fri Jan 27, 2017 12:07 pm
by afuchs
Dear Developers,

I need an element in author mode to act like a link, but dynamically: if there is an <xref> with @rid inside corresponding to a paragraph @id elsewhere, it should take the author to that paragraph.

Until this moment the paragraphs with the corresponding IDs were in another XML file with a filename that could be predicted from oxy_base-uri(), so that I could easily construct a link with some string functions in the CSS and leave it in place.

But now there is a new complication: if the ID referred to by the xref is present in the current file, the link should lead there; if not, it should be as described earlier (go to another file).

So that what I need is a switch, a test condition looking for a certain ID in the current file, and I have trouble constructing such a switch in the CSS. I considered adding a button which would activate an operation, but there is no author action for moving the caret or linking to another file that would work without additional Java programming.

To be less abstract, here is some pseudo from the CSS:

Code: Select all


	if (there is an element E in this document whose @id is equal to ./@rid) then
link: .#E (?)
else
link: oxy_concat(oxy_replace(oxy_base-uri(),"_extern",""), "#", attr(id));
end
Is there anything that could be done with this in a relatively inexpensive fashion?

Thank you in advance,
Alexey

Re: dynamic link construction for authors

Posted: Fri Jan 27, 2017 1:13 pm
by Radu
Hi Alexey,

With Java extension this could be done using our StylesFilter API:

https://www.oxygenxml.com/doc/versions/ ... ilter.html

Such an API would allow you to provide some kind of CSS layer but control from the Java code what style to set for a certain node.

Without a Java extension, we have a custom CSS function called oxy_xpath:

https://www.oxygenxml.com/doc/versions/ ... ction.html

I have not tested this but the CSS link property would thus have a value something like:

Code: Select all

link:oxy_xpath(oxy_concat("if(//*[@id=", attr(rid), "]) then '#", attr(id), "' else '", oxy_concat(oxy_replace(oxy_base-uri(),"_extern",""), "#", attr(id)), "'"));
Notice how I use oxy_concat inside of oxy_xpath to be able to call other CSS extension functions and have them expanded before the actual XPath is executed.

The oxy_xpath may induce performance problems, Oxygen does not know exactly on what nodes the selector which uses it depends on so on each modification anywhere in the document Oxygen will refresh the link node. It depends on how much your XML documents can grow, probably if they grow over half a megabyte the problem will be visible to the end user.

Regards,
Radu

Re: dynamic link construction for authors

Posted: Fri Jan 27, 2017 1:52 pm
by afuchs
Dear Radu,

Thank you so much. Especially for the tip for nesting oxy-functions - this was never very transparent for me and solves so much.

Regards,
Alexey