Page 1 of 1

Schematron quick fix to add and element and an attribute

Posted: Wed Oct 26, 2022 7:15 pm
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

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

Posted: Thu Oct 27, 2022 8:47 am
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

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

Posted: Thu Oct 27, 2022 11:23 am
by ann.jensen
Thank you very much Radu, that explains it.
Regards,
Ann