Page 1 of 1
How to replace entire document, including prolog
Posted: Tue Feb 21, 2023 12:04 am
by mboudreau
I have an XSLT conversion that takes an instance of one DTD (NLM Journal Publishing 3.0) and converts it to an instance of another DTD (JATS 1.2). When I run this conversion in a transformation scenario, it works as expected.
However, I want to build this conversion into an Action to be used in the framework for the first DTD. The action is defined as an XSLTOperation with these parameters:
- sourceLocation: /article
- targetLocation: /article
- action: Replace
The conversion runs, but instead of replacing the current article with the new instance, it generates the error message "Could not create an AuthorDocumentFragment. Cause: Content is not allowed in prolog."
I assume this is happening because the conversion creates an entire new document, including the prolog (XML declaration and doctype declaration) and root element. But the XSLTOperation simply replaces the old root element, which results in two prologs.
Is there a way to configure an action to replace the entire document, including the prolog?
Re: How to replace entire document, including prolog
Posted: Tue Feb 21, 2023 12:51 pm
by Martin Honnen
I would try whether sourceLocation allows you to provide solely / instead of /article. The same for targetLocation. But I haven't tested whether oXygen allows/supports that.
Re: How to replace entire document, including prolog
Posted: Tue Feb 21, 2023 3:19 pm
by Cosmin Duna
Hi,
Indeed, this action should replace the entire content.
What about creating a refactoring operation based on XSLT (
https://www.oxygenxml.com/doc/versions/ ... tions.html) and storing it in your framework:
https://www.oxygenxml.com/doc/versions/ ... operations ?
Best regards,
Cosmin
Re: How to replace entire document, including prolog
Posted: Tue Feb 21, 2023 7:45 pm
by mboudreau
Just to be clear about what I'm trying to accomplish--I begin with a document like this:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" "journalpublishing3.dtd">
<article article-type="research-article" dtd-version="3.0" xml:lang="en"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:atict="http://www.arbortext.com/namespace/atict">
...
</article>
and I want to replace it with a document like this (note the different doctype declaration):
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD UCP JATS (Z39.96) Journal Publishing DTD with OASIS Tables with MathML3 v1.2 20190208//EN" "JATS-journalpublishing-oasis-article1-mathml3.ucp.dtd">
<article article-type="research-article" dtd-version="1.2" xml:lang="en"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML">
...
</article>
My stylesheet includes
Code: Select all
<xsl:output method="xml" indent="no" cdata-section-elements="tex-math"
doctype-public="-//NLM//DTD UCP JATS (Z39.96) Journal Publishing DTD with OASIS Tables with MathML3 v1.2 20190208//EN"
doctype-system="JATS-journalpublishing-oasis-article1-mathml3.ucp.dtd"/>
I tried Martin's suggestion, so that the XSLTOperation has the following parameters:
- sourceLocation: /
- targetLocation: /
- script: ${framework}/xslt/ucp-jp2ucp-jats.xsl
- action: Replace
- caretPosition: First editable position
- expandEditorVariables: true
- suspendTrackChanges: false
- externalParams: [not specified]
- alwaysPreserveTrackedChangesBeforeProcessing: [not specified]
Unfortunately, the new result is the error message "The source Path location does not identify an element: /". In this case, the conversion doesn't appear to run at all (none of its diagnostic messages appear in the Messages tab).
When I had sourceLocation and targetLocation specified as "/article", I could tell that the conversion was running (because diagnostic messages appeared in the Messages tab), but apparently the replacement of the source <article> failed because the conversion output includes the XML declaration and doctype declaration as well as the new <article> element.
I have read the "Custom Refactoring Operations" page that Cosmin recommended, but as far as I can tell, it doesn't allow replacing the prolog as well as the root element, and in this case replacing the prolog is essential.
Re: How to replace entire document, including prolog
Posted: Wed Feb 22, 2023 1:01 pm
by Cosmin Duna
Hi,
The doctype can be changed using a custom refactoring operation.
For example, in Oxygen we have a refactoring operation that converts a DITA bookmap to a DITA map. The XSL file that makes this conversion is located here:
Oxygen_install_dir\frameworks\dita\map_refactoring\convertDITABookmapToMap.xsl and the template that change the doctype( <xsl:template name="convert-header">) is located here
Oxygen_install_dir\frameworks\dita\refactoring\dita-files-conversion-stylesheets\handle-schema-conversion.xsl
The documentation for modifying content outside the root element is here:
https://www.oxygenxml.com/doc/versions/ ... w_custom_r
Best regards,
Cosmin
Re: How to replace entire document, including prolog
Posted: Wed Feb 22, 2023 11:36 pm
by mboudreau
Thanks, Cosmin. I set up the custom refactoring operation, and it's working as intended.
At the moment, I can invoke it by clicking the XML Refactoring icon in the Toolbar, or by right-clicking inside the document in Author View and selecting 'Refactoring' and then the name of the custom operation. Is there a way to invoke the operation more directly, by linking it to an icon in the Toolbar? If not, I'd like to suggest that as a feature for future versions, so that refactoring operations can be treated similarly to Author Actions.
Re: How to replace entire document, including prolog
Posted: Thu Feb 23, 2023 11:46 am
by Cosmin Duna
Hi,
Unfortunately, you cannot directly add a specific XML Refactoring operation on the toolbar or menus. We already have an internal issue for this improvement and I added your request to it for increasing its priority.
Best regards,
Cosmin
Re: How to replace entire document, including prolog
Posted: Thu Feb 23, 2023 12:08 pm
by chrispitude
Please also add my name to this request. It would be nice to configure toolbar buttons or menu/submenu items that directly run certain common refactoring operations.
Re: How to replace entire document, including prolog
Posted: Thu Feb 23, 2023 2:27 pm
by Cosmin Duna
Hi Chris,
Sure. I added your feedback to the internal improvement request.
Best regards,
Cosmin