Page 1 of 1

Action to run multiple updates on the source document

Posted: Tue Jan 30, 2018 6:08 am
by mboudreau
I have an XSLT script that performs two types of actions on an XML document:
  1. Issues warnings (using <xsl:message>) if it finds markup errors it cannot correct
  2. Makes some easy corrections (e.g., change <month>1</month> to <month>01</month> throughout the document)
On the command line, this transformation can be invoked by a wrapper script (e.g., a Perl script) that replaces the original source file with the XSLT output.

From within Oxygen, I'd like to run this script and have it edit the source document without outputting a new result document. What Author Mode operations will do that?

Re: Action to run multiple updates on the source document

Posted: Tue Jan 30, 2018 4:08 pm
by alex_jitianu
Hello,

An XSLTOperation can do what you describe. The root element returned by the script will replace an element from within the document (it can be the root element if the operation is configured as such). The warnings emitted via xsl:message will be presented in the results area.
Issues warnings (using <xsl:message>) if it finds markup errors it cannot correct
You could extract this part from the script into a Schematron file which can be applied automatically on the document (if needed). Maybe even provide some quick fixes for the user (for those situation when there might be multiple fixes to an issue and you can't choose one automatically).

Best regards,
Alex

Re: Action to run multiple updates on the source document

Posted: Thu Feb 01, 2018 12:31 am
by mboudreau
Thanks, Alex. I set up the action as follows, and it does what I want:
Operation: XSLTOperation
Arguments
sourceLocation: /article
targetLocation: /article
script: ${framework}/xslt/verify.xsl
action: Replace
caretPosition: First editable position
expandEditorVariables: true
suspendTrackChanges: false
Now I'd like to be able to use the same XSLT script in Oxygen and on the command line as well, but I need its behavior to be slightly different in these two contexts, and I'm wondering if there's a way for XSLTOperation to pass a parameter to the XSLT script.

In brief, the file I'm viewing in Oxygen is a JATS article that looks like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ...>
<article ... >
...
</article>
On the command line, the XSLT script needs to output the doctype declaration, so it includes this:

Code: Select all

<xsl:output method="xml" xml:space="default" indent="yes" omit-xml-declaration="no" doctype-public="-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" doctype-system="journalpublishing3.dtd"/>
However, when I run the script via the XSLTOperation as configured above, I get a "content is not allowed in prolog" error. To fix this, I change the <xsl:output> element above to

Code: Select all

<xsl:output method="xml" xml:space="default" indent="yes"/>
Is there a way to update either my Action or my XSLT script so that it doesn't output the doctype declaration when run from Oxygen but does so when run from the command line?

Re: Action to run multiple updates on the source document

Posted: Thu Feb 01, 2018 4:17 pm
by alex_jitianu
Hello,

In the next version of Oxygen you will be able to send parameters to the XSLT script. Meanwhile, perhaps you can have a generic XSLT, one that doesn't specify any xsl:output and create two other driver XSLTs. One for the command line that imports the generic one and defines an xsl:output to generate the DOCTYPE and another for Oxygen that doesn't have the DOCTYPE part. This way you will still be sure that, when making a change, the code will run similarly in Oxygen and on the command line.

Best regards,
Alex