Best approach to automate insertion of DITA into all topicrefs in a project

Post here questions and problems related to editing and publishing DITA content.
ann.jensen
Posts: 295
Joined: Wed Jun 17, 2015 10:19 am

Best approach to automate insertion of DITA into all topicrefs in a project

Post 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
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Best approach to automate insertion of DITA into all topicrefs in a project

Post by chrispitude »

Hi ann.jensen,

I would do this with a refactoring operation.

Do you want the same identical @appname value in every <topicref>?
ann.jensen
Posts: 295
Joined: Wed Jun 17, 2015 10:19 am

Re: Best approach to automate insertion of DITA into all topicrefs in a project

Post 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
ann.jensen
Posts: 295
Joined: Wed Jun 17, 2015 10:19 am

Re: Best approach to automate insertion of DITA into all topicrefs in a project

Post 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
tavy
Posts: 365
Joined: Thu Jul 01, 2004 12:29 pm

Re: Best approach to automate insertion of DITA into all topicrefs in a project

Post 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
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
ann.jensen
Posts: 295
Joined: Wed Jun 17, 2015 10:19 am

Re: Best approach to automate insertion of DITA into all topicrefs in a project

Post 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
Post Reply