Page 1 of 1

Add xpath expression dynamically in Oxygen Web Author

Posted: Mon Nov 28, 2022 4:48 pm
by shreya
Hi,

So I want to add a xpath expression to an element which will be dynamic based on the "numchar" attribute value. If the value changes then the change to the value should reflect immediately. I have added the xpath expression through the framework and it works but it is not dynamic in the oxygen web author. How do I make it dynamic in web author? This is the expression that I added in framework css.

Code: Select all

charfill::before{ 
display:inline !important;
  content: oxy_xpath("substring(translate('-----------------------------------------------','-',substring(.,1,1)),1,number(@numchar)-1)", processChangeMarkers, true, evaluate, dynamic); 
}

Re: Add xpath expression dynamically in Oxygen Web Author

Posted: Tue Nov 29, 2022 5:36 pm
by Bogdan Dumitru
Hello,

This is a documented limitation, see the Oxygen XML Web Author CSS Limitations:
CSS property values that contain the oxy_xpath function are not updated correctly when the document changes.
To force the update of such a property, you can use the refresh(AuthorNode) method from AuthorEditorAccess.
You can manually call the "refresh()" method when needed.

Also, if you are willing to share what you actually want to achieve, we might be able to find an alternative solution. We sense that you want to create a TOC-like page but we are not sure. If that's the case, you might be able to use standard CSS rules (like border-bottom) to separate chapters or even CSS Paged Media just for print.

Re: Add xpath expression dynamically in Oxygen Web Author

Posted: Tue Nov 29, 2022 8:44 pm
by shreya
Actually it is an older code that I need to use as we are working on a migration.
I just need to add the xpath expression on the element charfill on load and also if the attribute numchar changes value anytime. So is there any way to track when an attribute changes in an element or is there any event for that?

Re: Add xpath expression dynamically in Oxygen Web Author

Posted: Wed Nov 30, 2022 10:37 am
by Bogdan Dumitru
Hello,

You can intercept changes by using an AuthorDocumentFilter by overriding the attribute-related methods (e.g: setAttribute()).

Re: Add xpath expression dynamically in Oxygen Web Author

Posted: Thu Dec 01, 2022 8:30 am
by shreya
Hi,
Will it work if I am changing the attribute value from the editor itself and not by using setAttribute() methods?

Re: Add xpath expression dynamically in Oxygen Web Author

Posted: Thu Dec 01, 2022 11:35 am
by Bogdan Dumitru
Yes.

Re: Add xpath expression dynamically in Oxygen Web Author

Posted: Thu Dec 01, 2022 1:30 pm
by shreya
Is there a sample code for using it? I am not sure where to add it?

Re: Add xpath expression dynamically in Oxygen Web Author

Posted: Fri Dec 02, 2022 12:41 pm
by cristi_talau
Hi,

As Bogdan said, you need to force a refresh of the "charfill" element when the "@numchar" attribute is changed.

One way to do this, is to register a server-side listener such as an AuthorDocumentFilter as Bogdan suggested or even an AuthorListener [1]. Here is some sample code that registers an AuthorDocumentFilter [2]. From this listener you need to call the "refresh" method of "AuthorEditorAccess" [3] on the "charfill" element.

Another way is to use a CSS hack to force refreshing the "charfill" element.

Code: Select all

charfill:after(100) {
  content: attr(numchar);
  display: none;
}
This CSS creates an invisible ":after" element that depends on the "numchar" attribute - so when the "numchar" attribute changes, the "charfill" element is re-rendered.

Best,
Cristian
[1] https://www.oxygenxml.com/InstData/Edit ... tener.html
[2] https://github.com/oxygenxml/web-author ... n.java#L34
[3] https://www.oxygenxml.com/InstData/Edit ... ccess.html

Re: Add xpath expression dynamically in Oxygen Web Author

Posted: Tue Dec 06, 2022 12:57 am
by shreya
Thank you so much. This absolutely helped, also I learnt something new in CSS.