cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

call Schematron from ACL menu item

SOLVED

Re: call Schematron from ACL menu item

I keep trying but get no results coming up when I run the menu item.

I tried changing how the reference path is for the schematron but cannot get success.

 

I'm not sure if it cannot find the schematron file (this menu.acl file I am working in is on the server, and server has an E drive, and other menu items seem to point to other files on E drive this way seem to work. I've also tried with the actual server name in place of "E").

Or maybe the validate_schematron() function isn't executing?

 

This is my menu item in menu.acl

if(!menu_exists(".$menu_name_condition.$menu_item_condition7")) { 
   menu_add .$menu_name_condition. "$menu_item_condition_show7" -cmd {validate_schematron("E:\DITA_Custom\custom\doctypes\condition-relaxed\drugTableValidation.sch", "Schematron 1 Errors"); }
}

and this is my function in menu.acl

 

function validate_schematron(schfile, log_name, doc=current_doc()) {
   local msgs[];
   validate_against_schematron(msgs, doc, schfile);
   schematron::add_errors_to_log(msgs, doc, log_name);
}

I'm not sure how to tell which part is failing, or how I should be consuming the Error report - would an event log window pop up similiar to check completeness if the drugTableValidation file was executed?

 

 

Re: call Schematron from ACL menu item

OK, I do see one problem that might be causing issues: if you are going to use Windows-style path separators ("\"), you'll need to use single quotes rather than double quotes around the file path. Using double quotes causes the backslashes to be interpreted as escape characters. So, try changing the command in your menu_add statement  to this:

validate_schematron('E:\DITA_Custom\custom\doctypes\condition-relaxed\drugTableValidation.sch', "Schematron 1 Errors");

To figure out what part of the script might be failing you can use response() calls to pop up status at various points in the script. So, you could try something like this:

unction validate_schematron(schfile, log_name, doc=current_doc()) {
   response("validate_schematron is running");
   local msgs[];
   local result = validate_against_schematron(msgs, doc, schfile);
   response("validate_against_schematron is done, generated " . count(msgs) . " messages");
   schematron::add_errors_to_log(msgs, doc, log_name);
   response("validate_schematron is done, exiting script");
}

If everything is working right, you should get popup messages indicating the progress through the script.

 

Note that if there are no errors in your document (i.e. none of the schematron rules triggers a message), seeing nothing is the expected result. So, when you are testing, make sure your document has some conditions that will generate warnings.

Re: call Schematron from ACL menu item

Hi Clay,

 

The response() seems to work really well!! Thank you. Great suggestion. The only problem is it says generated 0 messages when I run it, when there should be 2 offenders. If it did pick up on the schematron infractions, where would I see details about - in an Event log pop up window?

 

I know this file has 2 infractions because when I put the same <pattern>s into my regular schematron validation file, and run it via check completeness, I get 2 schematron infractions coming out.

 

When I have these same <pattern>s in a separate drugTableValidation.sch file, and run it from the menu, it says in the response() pop up  "0 generated messages". They are the exact same <rule>s though. head scratch.

Re: call Schematron from ACL menu item

In that case, try adding the value of the "result" variable to the response() output. If the value is -1, then something went wrong with the schematron validation--either it couldn't read the schematron file, or there was some kind of validity issue with the contents of the schematron file.

Re: call Schematron from ACL menu item

I added

response(validate_against_schematron(msgs, doc, schfile));

and I am getting '0' as the response

so then

In my menu item, as a test, I changed the menu item to point to our overall schematron of cpha-editor.sch, and ran the menu item, and still received '0' even though I should have 2 violations, so I think the schematron is not being set and passed from the menu item to the validate_schematron function for some reason

Re: call Schematron from ACL menu item

This is how I have it right now

if(!menu_exists(".$menu_name_condition.$menu_item_condition7")) { 
	menu_add .$menu_name_condition. "$menu_item_condition_show7" -cmd {validate_schematron('E:\DITA_Custom\custom\doctypes\condition-relaxed\drugTableValidation.sch', "Schematron 1 Errors"); }
}
function validate_schematron(schfile, log_name, doc=current_doc()) {
   response("validate_schematron is running");
   local msgs[];
   local result = validate_against_schematron(msgs, doc, schfile);
   response(validate_against_schematron(msgs, doc, schfile));
   response("validate_against_schematron is done, generated " . count(msgs) . " messages");
   validate_against_schematron(msgs, doc, schfile);
   schematron::add_errors_to_log(msgs, doc, log_name);
   response("validate_schematron is done, exiting script");
}

Re: call Schematron from ACL menu item

I guess the next step is to add a line in your validate_schematron function to explicitly check for the schematron file, something like this:

function validate_schematron(schfile, log_name, doc=current_doc()) {
   response("validate_schematron is running");
   if (!access(schfile, "e")) {
      response("Couldn't find schematron file " . schfile);
   }
   local msgs[];
   local result = validate_against_schematron(msgs, doc, schfile);
   response("validate_against_schematron is done, generated " . count(msgs) . " messages");
   schematron::add_errors_to_log(msgs, doc, log_name);
   response("validate_schematron is done, exiting script");
}

That should tell you if it's having trouble interpreting the path of the schematron file.

Re: call Schematron from ACL menu item

that's it - thank you!

the function received the path from the menu item, but it cannot find the drugTableValidation schematron file.

the name comes up in the error message, so menu item is passing it to the function, but function cannot find it.

 

I've tried so many variations of the file path

double slashes, using the full path including the server name etc. I can't figure out why it cannot find the file

Re: call Schematron from ACL menu item

It should understand the same type of path that Windows understands. The easiest way to figure out the right path to use is to open the schematron file itself in Editor, and then use the Session Info panel to find the document path:

 

  1. From the menus choose Help->Session
  2. In the Session window, select the Document tab
  3. Read the location of the document from the first line in the table

If you use the same path you find there in your script, it should be able to read the file and apply it.

Re: call Schematron from ACL menu item

I got results!!!!

When I used the path as you suggested, my 2 infractions came up.

The issue was I was using E:\ which is the drive on the server, but my computer maps that server using the G drive. Other users may select different letters so I saved the schematron in a common folder on a drive everyone uses i.e. S:\ drive... S for "shared" and pointed the menu item there, and it WORKS.

 

 

Thank you Clay, so very  much, for all the help.

The schematron menu item solution is now up and running Smiley Very Happy