oxy_xpath with doc() in css, or force an action from oxy_combobox

<oXygen/> general issues.
Doug
Posts: 28

oxy_xpath with doc() in css, or force an action from oxy_combobox

Fri Jan 20, 2017 12:35 am

I have a problem where I have a document with elements with a code attribute with numerical values that ideally should be looked up in another document to get a text meaning for the code.

I've tried to use the below css style (simplified with a hard coded code value). Only the "Test: " string is visible in the styled document. If I don't concat anything to the xpath results, nothing is displayed. I know the url path in doc() is right because if I deliberately make it incorrect I get an error message for every case of socm element when the document is styled, so I also know that the doc() function is being executed.

socm[code]:before {
display: inline;
content: oxy_concat("Test: ", oxy_xpath("doc('file:/C:/Users/Doug/Documents/work/collection_materials/frameworks/docbook/css/ocm.xml')//category[@code='101']/@term/string()"));
font-size: 10pt;
color:blue;
text-transform: capitalize;
}


A snippet of the lookup document is like:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<category code="100" term="ORIENTATION">
</category>
<category code="101" term="IDENTIFICATION">
</category>
<category code="102" term="MAPS">
</root>

Alternatively I could add a separate attribute of @term on the socm element with the corresponding text for code value, but I don't really want the text to be static in the styled document, and, two, I am allowing new code values to be changed with a combobox form and I can only update one attribute with the combobox. Is there anyway to trigger an action from a combobox to update the corresponding term attribute?

A snippet from the styled document, with less desirable corresponding term attribute looks like:
<sowc code="aw11" term="Kerala">
<socm code="101" term="Identification"/>
<socm code="131" term="Location"/>
<socm code="133" term="Topography and geology"/>
<socm code="174" term="Historical reconstruction"/>
</sowc>
</sid>
alex_jitianu
Posts: 600

Re: oxy_xpath with doc() in css, or force an action from oxy_combobox

Fri Jan 20, 2017 4:06 pm

Hi Doug,

In my tests the CSS worked. I've changed it a bit, like this:

Code: Select all

socm[code]:before {
display: inline;
content: "Test: " oxy_xpath(oxy_concat("doc('ocm.xml')//category[@code='", attr(code),"']/@term/string()"));
font-size: 10pt;
color:blue;
text-transform: capitalize;
}


Do you, by any change, have a default namespace declared inside ocm.xml ? Because if you do, then you have to take it into account when writing the XPath expression: *:category

I will send you some sample files (created after your examples) on your email address to see if they work for you too.

Best regards,
Alex
Doug
Posts: 28

Re: oxy_xpath with doc() in css, or force an action from oxy_combobox

Fri Jan 20, 2017 9:11 pm

Thanks Alex. You guys are the greatest! What service supporting a great product.

So here's the story: My code wasn't so far off yours and while your code with the three test files you sent worked perfectly in my Oxygen installation, I still couldn't get mine to work even when paring it down to be almost exactly the same as yours. But your code proved it should work and in my environment.

My problem: namespace.

How many times have I needed to remember when the obvious isn't obvious check my namespacing. My main styled document which is a variant of docbook declared a default docbook namespace. My lookup ocm document had no namespace. I experimented first with declaring my lookup ocm.xml document as docbook and that worked! Since the ocm.xml document isn't at all a docbook document I improved this by declaring a unique ocm namespace and declaring it with appropriate prefix in the css file and as default in my lookup ocm document and referencing the lookup element in the css with that namespace and everything worked great. I can now use this lookup technique in several other places in my styling which is going to make for much more normalized and manageable code.

Specifically I now have:

In the styled main document: aw11_collection_materials.xml:
<?xml version="1.0" encoding="UTF-8"?>
<book xmlns="http://docbook.org/ns/docbook"

In the css style sheet: hraf.docbook.css
@namespace ocm url("http://hraf.org/ns/ocm");
and:
content: "Test: " oxy_xpath(oxy_concat("doc('../../frameworks/docbook/css/ocm.xml')//ocm:category[@code='", attr(code),"']/@term/string()"));

In the lookup document: ocm.xml
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://hraf.org/ns/ocm">

Doug
Doug
Posts: 28

Re: oxy_xpath with doc() in css, or force an action from oxy_combobox

Fri Jan 20, 2017 9:20 pm

Rereading your post Alex I see you suspected namespace might be the issue too. The only difference from your theory is my problem was the reverse, my default namespace was in my main file and the lookup ocm.xml file had no namespace, but the effect was the same.
alex_jitianu
Posts: 600

Re: oxy_xpath with doc() in css, or force an action from oxy_combobox

Wed Jan 25, 2017 12:23 pm

Hi Doug,

I'm glad you found the culprit! So because the XPath is invoked inside the context of the main file, when it jumps inside "ocm.xml" it keeps the default namespace... Not what you'd expect... I'll have to investigate a bit more.

Best regards,
Alex
sorin_carbunaru
Site Admin
Posts: 111

Re: oxy_xpath with doc() in css, or force an action from oxy_combobox

Mon Oct 02, 2017 4:26 pm

Hello,

Just wanted to let you know that in the recently released oXygen 19.1 we added a new CSS property to oxy_combobox , called onChange. It can be used to invoke an action when the value of the combo box changes. The action can be created in the CSS using the "oxy_action()" function or referred from a framework by its ID.

For more information and an example see https://www.oxygenxml.com/doc/versions/ ... ditor.html.

Best wishes,
Sorin Carbunaru
oXygen XML

Return to “Other Issues”

Who is online

Users browsing this forum: No registered users and 3 guests