Schematron quick fix to add and element and an attribute

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

Schematron quick fix to add and element and an attribute

Post by ann.jensen »

Hi,
I think I am trying to do something simple with Schematron and quick fixes but struggling.
I want to check for a given element and if it doesn't exist, then I want to add it and its required attribute.
I know I need

Code: Select all

  <sch:rule context="prolog">
            <sch:assert test="resourceid" sqf:fix="addResource">ResourceId element is missing. </sch:assert>            
            <sqf:fix id="addResource">
                <sqf:description><sqf:title>Add resourceId inside prolog</sqf:title></sqf:description>
                    <sqf:add target="resourceid" node-type="element" position="last-child"></sqf:add>            
            </sqf:fix>
        </sch:rule>             

to add the missing element (resourceid) but not sure how I also add the required attribute name and value (appname="abc") in the same fix.

Any advice appreciated,
Regards,
Ann
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Schematron quick fix to add and element and an attribute

Post by Radu »

Hi Ann,

Maybe you can take a look at my "addProlog" quick fix from the Oxygen XML Blog project:
https://github.com/oxygenxml/blog/blob/ ... /rules.sch

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
ann.jensen
Posts: 295
Joined: Wed Jun 17, 2015 10:19 am

Re: Schematron quick fix to add and element and an attribute

Post by ann.jensen »

Thank you very much Radu, that explains it.
Regards,
Ann
Post Reply