Page 1 of 1
Best approach to automate insertion of DITA into all topicrefs in a project
Posted: Tue Nov 09, 2021 8:35 pm
by ann.jensen
Hi,
I have a section of DITA XML
Code: Select all
<topicmeta>
<resourceid appname="abc"/>
</topicmeta>
that I want to insert within all instances of <topicref></topicref> in my project maps.
Some of them might already have some of this XML already there in which case I don't want to overwrite it.
Can you advise the most efficient way to set this up within Oxygen Editor please?
I am thinking
1. Use a Schematron rule but can the fix be auto applied or do I have to manually commit each fix
2. Use a Find/Replace in files with a Regular Expression.
However I am sure there are better solutions available that I am not aware of.
Any advice appreciated,
Regards,
Ann
Re: Best approach to automate insertion of DITA into all topicrefs in a project
Posted: Wed Nov 10, 2021 4:46 am
by chrispitude
Hi ann.jensen,
I would do this with a refactoring operation.
Do you want the same identical @appname value in every <topicref>?
Re: Best approach to automate insertion of DITA into all topicrefs in a project
Posted: Wed Nov 10, 2021 1:00 pm
by ann.jensen
Hi yes, if there is no
Code: Select all
<topicmeta><resourceid appname="ABC"/></topicmeta>
in a <topicref> then I want to insert this into it
Thanks,
Ann
Re: Best approach to automate insertion of DITA into all topicrefs in a project
Posted: Wed Nov 10, 2021 2:07 pm
by ann.jensen
Hi,
I have created a Schematron rule and quickfix that will insert the XML fragment when detected.
However, the <sqf:add> is also inserting
Code: Select all
xmlns="http://purl.oclc.org/dsdl/schematron"
as an attribute of the root XML element in my fragment as follows:
Code: Select all
<topicmeta xmlns="http://purl.oclc.org/dsdl/schematron">
<resourceid appname="abc"/>
</topicmeta>
Is there any way I can prevent this from being generated?
Thanks,
Ann
Re: Best approach to automate insertion of DITA into all topicrefs in a project
Posted: Mon Nov 15, 2021 10:27 am
by tavy
Hello Ann,
I am not sure why the Schematron namespace is added. Probably you define the Schematron namespace as default namespace instead of using a prefix, something like
xmlns:sch="http://purl.oclc.org/dsdl/schematron".
You can find below an example of Schematron rule that can be applied on your map. It offers also two quick fix actions that allows you to add a topicmeta on the current topicref element or in all topicref elements from the map.
Code: Select all
<sch:rule context="topicref">
<sch:assert test="topicmeta" sqf:fix="addTopicmeta addAllTopicmeta">
topicmeta element is missing. </sch:assert>
<sqf:fix id="addTopicmeta">
<sqf:description>
<sqf:title>Add topicmeta element</sqf:title>
</sqf:description>
<sqf:add target="topicmeta" node-type="element">
<topicmeta>
<resourceid appname="abc"/>
</topicmeta>
</sqf:add>
</sqf:fix>
<sqf:fix id="addAllTopicmeta">
<sqf:description>
<sqf:title>Add topicmeta element in all topicref</sqf:title>
</sqf:description>
<sqf:add match="//topicref[not(topicmeta)]">
<topicmeta>
<resourceid appname="abc"/>
</topicmeta>
</sqf:add>
</sqf:fix>
</sch:rule>
Best Regards,
Octavian
Re: Best approach to automate insertion of DITA into all topicrefs in a project
Posted: Mon Nov 15, 2021 2:03 pm
by ann.jensen
Thank you Octavian. Yes, I changed the namespace declaration as you advised and the namespace is not being added to the generated DITA XML now.
Regards,
Ann