Custom functions in CSS oxy_url()

Post here questions and problems related to oXygen frameworks/document types.
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Custom functions in CSS oxy_url()

Post by steve.cuzner »

according to https://www.oxygenxml.com/doc/versions/ ... ction.html you can use a function as one of the components to the oxy_url() function. I've added a function to my framework commons.js file

Code: Select all


function resolvehref(href) {
return "http://www.google.com";
}
when I add this to oxy_url()

Code: Select all


someSelector {
link: oxy_url(resolvehref(attr(href))) !important;
}
I get an error that the the function can't be found:

Code: Select all

Context : someSelector : link Unknown function: "resolvehref" : oxy_url (resolvehref ())
Are only Oxygen functions supported or is there some additional glue that I need to call my own function?
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: Custom functions in CSS oxy_url()

Post by steve.cuzner »

I edited the simplify but missed the function definition that I modified to take no arguments.
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom functions in CSS oxy_url()

Post by Radu »

Hi Steve,

Right now you cannot add extra functions to the set of CSS functions that Oxygen knows about. We have an issue for this and we might approach it in a future version.
We do have an oxy_xpath function:

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

which executes an XPath 2.0 expression and XPath is quite powerful also in manipulating strings.
We also have support to add a Java StylesFilter API which would allow you to take control over how CSS styles are computed like for example:
https://www.oxygenxml.com/doc/versions/ ... ilter.html

Maybe as a possible enhancement in the future we could have an "oxy_js" CSS function which would allow you to run Javascript code set as a parameter to the function.

Could you tell me more about what the real implementation of the "resolvehref" would need to do?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: Custom functions in CSS oxy_url()

Post by steve.cuzner »

We have a custom element that has a link attribute that contains a symbolic reference to a destination. We do this so we can have the link resolve to different locations, such as draft vs final. We would use the js to evaluate the proper environment to use to create a physical link address.

Regarding the use the the oxy_xpath function, is that limited to the current document, or could the xpath be anchored to an secondary xml file using the document() function? Would that introduce performance issues?
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom functions in CSS oxy_url()

Post by Radu »

Hi Steve,

Thanks for presenting your use-case.
The oxy_xpath can execute any XPath 2.0 expression, including the possibility to load XML files.
As stated in the user guide in the link I previously gave you it may induce performance problems. It has a parameter called evaluate which can be set to various values in order to avoid Oxygen performing lots of computations every time something changes. For example if the XPath is executed over an external XML and its results would not change depending on the CSS selector element on which the oxy_xpath is placed, you could use:

Code: Select all

 oxy_xpath(
"document(a.xml)//@val",
evaluate,
static)
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: Custom functions in CSS oxy_url()

Post by steve.cuzner »

Is it possible to use Oxygen variables in the xpath, such as ${pdu}?
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom functions in CSS oxy_url()

Post by Radu »

Hi Steve,

As far as I know the oxy_xpath does not expand editor variables but the oxy_url does so you can do stuff like this:

Code: Select all

 content:  oxy_xpath(oxy_concat('document(', oxy_url('${pdu}', 'a.xml'), ')//@val'),
in order to compose the xpath expression from various parts.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: Custom functions in CSS oxy_url()

Post by steve.cuzner »

This doesn't seem to be working as expected. Here is the code:

Code: Select all

link[xlink|href]:empty{
content:oxy_xpath(oxy_concat('document(', oxy_url('${pdu}', 'a.xml'), ')//@val')) !important;
}
The entire content of a.xml, which is in the same folder as the current xpr file is

Code: Select all

<a val="my content"/>
In the CSS Inspector I can see that this selector is at the top of the list, but the content of the val attribute isn't being output as content.
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom functions in CSS oxy_url()

Post by Radu »

Hi Steve,

I made it work with something like this:

{code}content:oxy_xpath(oxy_concat('doc("', oxy_url('${pdu}/', 'a.xml'), '")//@val')) !important;{code}

The document() function is an XSLT addition to XPath so it cannot be used when running standalone XPath expressions, but you can use doc instead. Also both the doc and document functions require their string literal parameters to be quoted something like doc("file:c:/a/b/c.xml") so I added extra quotes to the literal expressions.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: Custom functions in CSS oxy_url()

Post by steve.cuzner »

That Worked! Thank you so much.

Steve
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: Custom functions in CSS oxy_url()

Post by steve.cuzner »

One more problem: if the file a.xml has an xinclude to b.xml where @val is, the xincludes don't seem to be expanded and the oxy_xpath seems to fail. Is there a flat on the doc function to expand xincludes? Also, where is the documentation for the doc function?
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: Custom functions in CSS oxy_url()

Post by steve.cuzner »

This thread seems to answer my question:

topic9894.html
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: Custom functions in CSS oxy_url()

Post by alex_jitianu »

Hi Steve,

Actually, starting with version 17.1, oxy_xpath() also expands xincludes. What Oxygen version are you using?

Best regards,
Alex
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: Custom functions in CSS oxy_url()

Post by steve.cuzner »

18.1 is my version, but the same code that works with a "flattened" file doesn't work with xinclude references (three deep).
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: Custom functions in CSS oxy_url()

Post by alex_jitianu »

Hi Steve,

Perhaps you have disabled the XInclude processing? Please go to Options->Preferences on page XML / XML Parser and make sure that "Enable XInclude processing" is selected. If this isn't the cause then perhaps you can send me a small sample on support@oxygenxml.com.

Best regards,
Alex
steve.cuzner
Posts: 72
Joined: Thu Mar 26, 2015 4:57 pm

Re: Custom functions in CSS oxy_url()

Post by steve.cuzner »

That doesn't appear to be it, every checkbox on that page, xml/ xml parser, is checked.
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: Custom functions in CSS oxy_url()

Post by alex_jitianu »

Hi Steve,

I've sent you some sample files on your email address. These sample files work for me so perhaps we can compare them with your own and draw a conclusion...

Best regards,
Alex
sorin_carbunaru
Posts: 402
Joined: Mon May 09, 2016 9:37 am

Re: Custom functions in CSS oxy_url()

Post by sorin_carbunaru »

Hi,

Just wanted to let you know that oXygen 19.0 has been released two days ago and in this version the oxy_xpath() CSS function supports editor variables.

Best wishes,
Sorin Carbunaru
oXygen XML
Post Reply