Custom functions in CSS oxy_url()

Post here questions and problems related to oXygen frameworks/document types.
steve.cuzner
Posts: 64

Custom functions in CSS oxy_url()

Tue Dec 06, 2016 12:23 am

according to https://www.oxygenxml.com/doc/versions/18.1/ug-editor/concepts/dg-url-function.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: 64

Re: Custom functions in CSS oxy_url()

Tue Dec 06, 2016 12:25 am

I edited the simplify but missed the function definition that I modified to take no arguments.
Radu
Posts: 5088

Re: Custom functions in CSS oxy_url()

Tue Dec 06, 2016 11:44 am

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/18.1/ug-editor/concepts/dg-xpath-function.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/18.1/ug-editor/topics/api_faq_add_form_control_from_filter.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: 64

Re: Custom functions in CSS oxy_url()

Tue Dec 06, 2016 6:49 pm

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: 5088

Re: Custom functions in CSS oxy_url()

Wed Dec 07, 2016 11:19 am

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: 64

Re: Custom functions in CSS oxy_url()

Wed Dec 14, 2016 6:34 pm

Is it possible to use Oxygen variables in the xpath, such as ${pdu}?
Radu
Posts: 5088

Re: Custom functions in CSS oxy_url()

Thu Dec 15, 2016 10:43 am

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: 64

Re: Custom functions in CSS oxy_url()

Fri Dec 23, 2016 12:55 am

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: 5088

Re: Custom functions in CSS oxy_url()

Fri Dec 23, 2016 9:33 am

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: 64

Re: Custom functions in CSS oxy_url()

Fri Dec 23, 2016 5:08 pm

That Worked! Thank you so much.

Steve
steve.cuzner
Posts: 64

Re: Custom functions in CSS oxy_url()

Fri Dec 23, 2016 5:54 pm

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: 64

Re: Custom functions in CSS oxy_url()

Fri Dec 23, 2016 6:18 pm

This thread seems to answer my question:

https://www.oxygenxml.com/forum/topic9894.html
alex_jitianu
Posts: 600

Re: Custom functions in CSS oxy_url()

Wed Dec 28, 2016 12:03 pm

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: 64

Re: Custom functions in CSS oxy_url()

Wed Dec 28, 2016 4:56 pm

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: 600

Re: Custom functions in CSS oxy_url()

Wed Dec 28, 2016 5:29 pm

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: 64

Re: Custom functions in CSS oxy_url()

Wed Dec 28, 2016 5:40 pm

That doesn't appear to be it, every checkbox on that page, xml/ xml parser, is checked.
alex_jitianu
Posts: 600

Re: Custom functions in CSS oxy_url()

Thu Dec 29, 2016 5:18 pm

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
Site Admin
Posts: 111

Re: Custom functions in CSS oxy_url()

Fri Apr 07, 2017 12:30 pm

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

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 1 guest