Add xpath expression dynamically in Oxygen Web Author

Having trouble installing Oxygen? Got a bug to report? Post it all here.
shreya
Posts: 29
Joined: Mon Jun 27, 2022 9:09 pm

Add xpath expression dynamically in Oxygen Web Author

Post 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); 
}
Bogdan Dumitru
Site Admin
Posts: 71
Joined: Tue Mar 20, 2018 5:28 pm

Re: Add xpath expression dynamically in Oxygen Web Author

Post 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.
Bogdan Dumitru
http://www.oxygenxml.com
shreya
Posts: 29
Joined: Mon Jun 27, 2022 9:09 pm

Re: Add xpath expression dynamically in Oxygen Web Author

Post 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?
Bogdan Dumitru
Site Admin
Posts: 71
Joined: Tue Mar 20, 2018 5:28 pm

Re: Add xpath expression dynamically in Oxygen Web Author

Post by Bogdan Dumitru »

Hello,

You can intercept changes by using an AuthorDocumentFilter by overriding the attribute-related methods (e.g: setAttribute()).
Bogdan Dumitru
http://www.oxygenxml.com
shreya
Posts: 29
Joined: Mon Jun 27, 2022 9:09 pm

Re: Add xpath expression dynamically in Oxygen Web Author

Post by shreya »

Hi,
Will it work if I am changing the attribute value from the editor itself and not by using setAttribute() methods?
Bogdan Dumitru
Site Admin
Posts: 71
Joined: Tue Mar 20, 2018 5:28 pm

Re: Add xpath expression dynamically in Oxygen Web Author

Post by Bogdan Dumitru »

Yes.
Bogdan Dumitru
http://www.oxygenxml.com
shreya
Posts: 29
Joined: Mon Jun 27, 2022 9:09 pm

Re: Add xpath expression dynamically in Oxygen Web Author

Post by shreya »

Is there a sample code for using it? I am not sure where to add it?
cristi_talau
Posts: 436
Joined: Thu Sep 04, 2014 4:22 pm

Re: Add xpath expression dynamically in Oxygen Web Author

Post 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
shreya
Posts: 29
Joined: Mon Jun 27, 2022 9:09 pm

Re: Add xpath expression dynamically in Oxygen Web Author

Post by shreya »

Thank you so much. This absolutely helped, also I learnt something new in CSS.
Post Reply