Home Forums DITA and XMetaL Discussion CSS challenge Reply To: CSS challenge

Derek Read

Reply to: CSS challenge

This script will highlight all the “unwanted” titles (matching your description of unwanted):

[code]//XMetaL Script Language JScript:
var rng = ActiveDocument.Range;
var unwantedTitles = ActiveDocument.getNodesByXPath(“//section/title[position() > 1]”);
for (i=0;i rng.SelectNodeContents(unwantedTitles(i));
rng.ContainerStyle = “background-color:yellow; color:red”;

There are various events this can be called from but as you are writing an XMAX application you have control over when the user can save and when they can validate, so you could add this code before or after any other code you have written that runs when the user indicates (using your UI) that they want to perform either of these actions. Ultimately you are making the call to the XMAX Save() method.

Again, since this is XMAX which does not provide a “Validation Log” (as Author does) you will have built something analogous (if you are displaying validation errors to the end user). You could add additional errors into whatever you are displaying to the user, perhaps like the following:
“Corporate standards do not allow sections to contain titles anywhere except as the first element. Please remove all highlighted titles.”

Or you might throw up a different “Business Rules Violation” dialog that contains these types of errors (for users that question why this is valid DITA, but still not allowed). That would distinguish it from your “standard” list that gets its list of validation errors from the ValidationErrorList API.

So, your logic for your save action would perform this check (using a similar script to the one above) and if it fails (ie: the node count is > 0) you would just not call the Save() method (and then optionally tell the user why).

You might prompt the user with something like this:
“Corporate standards do not allow

elements to contain a anywhere except as the first child element. Would you like to remove unwanted elements? [Yes / No]”</p> <p>Then if they answer “Yes” you would have a similar script to the one above that would move to each unwanted title element and remove it from the document. In this case Save() could then be called as the document would then meet your standards.</p> <p>If the user answers “No” you might highlight them all so it is clear which are unwanted. In this case the user might move the text they contain somewhere else, or use it as a reference to rewrite a paragraph or something before doing the deletions.</p> <p>Or maybe you just tell the user the document is going to be “fixed” and you don't even give them a choice, then remove the elements automatically and call <tt>Save()</tt>.