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
Regular Member

call Schematron from ACL menu item

We are using schematron for extra validation of our xml documents during the standard 'Check Completeness' function and working well.

 

We would like to create a separate menu item for a different schematron (a subset of <pattern>s) only to be run by certain users employees. We would like this second Schematron to be kicked off from a custom menu item using ACL.

 

I can create a menu no problem, but how can I get my menu item to reference the schematron file? Where should this schematron file be saved?

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: call Schematron from ACL menu item

Hi Ashley--

 

See the documentation for the ACL function "validate_against_schematron" in the Arbortext Help Center: https://support.ptc.com/cs/help/arbortext_hc/ae61_hc/index.jspx?id=help17197&action=show. This is the function you'll want to apply ad hoc schematron checks to a document.

 

--Clay

30 REPLIES 30

Re: call Schematron from ACL menu item

Hi Ashley--

 

See the documentation for the ACL function "validate_against_schematron" in the Arbortext Help Center: https://support.ptc.com/cs/help/arbortext_hc/ae61_hc/index.jspx?id=help17197&action=show. This is the function you'll want to apply ad hoc schematron checks to a document.

 

--Clay

Re: call Schematron from ACL menu item

I am trying to implement this solution, and I have the function set up in my menu.acl

 

but it does not like the '0' arguement

 

function validate_against_schematron($S, 0, "cpha-editor.sch");

 

I get an error that says Unexpected Argument: 0,

 

I want the user to be able to open AE and then open the document, and run this schematron validation from a menu item, so 0 wont be set on initialization of AE, how can I work around this? what else can I put in instead of 0?

 

Re: call Schematron from ACL menu item

I would use something like this:

 

 

menu_add ".Tools." "Schematron Check" -cmd { validate_against_schematron($S, 0, "cpha-editor.sch"); }

Note that this will fill the $S array with any validation error messages, it will be up to you to display these to the user, or do something else with them.

 

If you just want to show the errors to the user, the easiest thing is probably to leverage the built-in "schematron" package code. There is a function defined there that does both the validation check and error message display, so maybe it's more direct to just use that. The function is called schematron::completeness_check_callback(doc, logname). So you could use something like this:

 

menu_add ".Tools." "Schematron Check" -cmd { schematron::completeness_check_callback(current_doc(), "Schematron Errors"); }

You may also need to make sure the schematron package is loaded before you can use this, so you can add a line near the top of your script file:

require schematron;

 

 

 

 

 

Re: call Schematron from ACL menu item

Thank you so much for breaking this down for me Clay!

I am getting somewhere.

 

I have the menu item appearing now with your second suggestion

It looks like this

 

if(!menu_exists(".$menu_name_condition.$menu_item_condition7")) {
menu_add .$menu_name_condition. "$menu_item_condition_show7" -cmd { schematron::completeness_check_callback(current_doc(), "Schematron Errors");}
}

 

and

require schematron;

at the top of my menu.acl file

I can now open AE without an errors.

 

I open a DITA document, run the new menu item, but I don't get any results from it. i.e. nothing comes up in an event log window that says "Schematron Errors" but the document I am using for sure has some.

 

Additionally, I do not want to run the overall schematron validation that we use for all our files (cpha-editor.sch) but instead I'd like to run another small schematron file that is checking for very specific things in particular documents.

 

This file is called drugTableValidation.sch, and it is stored in a different \doctype folder than the cpha-editor.sch schematron, which is the one that runs along with the usual Check Completeness schema validation.

 

 

We have a handful if schematron files like this, for these special use ones, I'd like to create ad hoc menu items to run them, and have that menu item NOT run the larger schematron validation we use for all the files.

 

 

 

Re: call Schematron from ACL menu item

OK, if you want to run specific schematron files, you'll probably have to go back to using validate_against_schematron(), and using calling the schematron logging function add_errors_to_log() to show the messages.

 

You can start by defining a function something like this:

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);
}

Then, your menu items can call this function with specific schematron files:

menu_add ".Tools." "Schematron 1" -cmd { validate_schematron("rules1.sch", "Schematron 1 Errors"); }
menu_add ".Tools." "Schematron 2" -cmd { validate_schematron("rules2.sch", "Schematron 2 Errors"); }
...etc...

Re: call Schematron from ACL menu item

Yesssss

Thank you Clay this is precisely what I am going for!

Almost there....

 

When i implement this, I get an error on AE initialization saying

Unrecognized function call: validate_against_schematron (msgs, doc, schfile)

 

validate_schematron is defined in the menu.acl file

but

Does the validate_against_schematron function have to be defined anywhere?

Do I need to make an .acl file for it in \scripts?

If so, what would I put in it?

 

 

Also, does it matter where drugTableValidation.sch is in the folder structure for the menu item to find it? Do I need to include a breadcrumb file path in the menu item for it or just the file name is sufficient?

 

 

Re: call Schematron from ACL menu item

Yes, that's what the line

require schematron;

is for. Make sure that appears at the top of any file that tries to call a schematron function and it should work.

 

This case is a little unusual, because validate_against_schematron() is defined in schematron.acl, but it is in the main::* package. If using "require schematron" doesn't fix the problem, try this instead:

autoload main::validate_against_schematron schematron

 

Re: call Schematron from ACL menu item

oops

when i put require schematron; back in, AE opens no problem

 

Also, menu item appears.

 

I click to run it, and nothing happens. I was expecting an event log window to pop up that says "Schematron 1 Errors".

In my menu item, i have

 

	if(!menu_exists(".$menu_name_condition.$menu_item_condition7")) { 
		menu_add .$menu_name_condition. "$menu_item_condition_show7" -cmd {validate_schematron("drugTableValidation.sch", "Schematron 1 Errors"); }
}

Do i need to put in a path for where my drugTableValidation.sch file is? or does it have to be in \scripts, or where should I put it? right now it is in \doctypes\[appropriate_subfolder]

 

Re: call Schematron from ACL menu item

Yes, you might need to include a path to the SCH file.