Page 1 of 1

Custom functions in CSS oxy_url()

Posted: Tue Dec 06, 2016 12:23 am
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?

Re: Custom functions in CSS oxy_url()

Posted: Tue Dec 06, 2016 12:25 am
by steve.cuzner
I edited the simplify but missed the function definition that I modified to take no arguments.

Re: Custom functions in CSS oxy_url()

Posted: Tue Dec 06, 2016 11:44 am
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

Re: Custom functions in CSS oxy_url()

Posted: Tue Dec 06, 2016 6:49 pm
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?

Re: Custom functions in CSS oxy_url()

Posted: Wed Dec 07, 2016 11:19 am
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

Re: Custom functions in CSS oxy_url()

Posted: Wed Dec 14, 2016 6:34 pm
by steve.cuzner
Is it possible to use Oxygen variables in the xpath, such as ${pdu}?

Re: Custom functions in CSS oxy_url()

Posted: Thu Dec 15, 2016 10:43 am
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

Re: Custom functions in CSS oxy_url()

Posted: Fri Dec 23, 2016 12:55 am
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.

Re: Custom functions in CSS oxy_url()

Posted: Fri Dec 23, 2016 9:33 am
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

Re: Custom functions in CSS oxy_url()

Posted: Fri Dec 23, 2016 5:08 pm
by steve.cuzner
That Worked! Thank you so much.

Steve

Re: Custom functions in CSS oxy_url()

Posted: Fri Dec 23, 2016 5:54 pm
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?

Re: Custom functions in CSS oxy_url()

Posted: Fri Dec 23, 2016 6:18 pm
by steve.cuzner
This thread seems to answer my question:

topic9894.html

Re: Custom functions in CSS oxy_url()

Posted: Wed Dec 28, 2016 12:03 pm
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

Re: Custom functions in CSS oxy_url()

Posted: Wed Dec 28, 2016 4:56 pm
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).

Re: Custom functions in CSS oxy_url()

Posted: Wed Dec 28, 2016 5:29 pm
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

Re: Custom functions in CSS oxy_url()

Posted: Wed Dec 28, 2016 5:40 pm
by steve.cuzner
That doesn't appear to be it, every checkbox on that page, xml/ xml parser, is checked.

Re: Custom functions in CSS oxy_url()

Posted: Thu Dec 29, 2016 5:18 pm
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

Re: Custom functions in CSS oxy_url()

Posted: Fri Apr 07, 2017 12:30 pm
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