Schematron rules for NIEM association elements

This should cover W3C XML Schema, Relax NG and DTD related problems.
cjhukill
Posts: 11

Schematron rules for NIEM association elements

Fri Jan 13, 2017 12:41 am

I am trying to build a schematron rule set for an XML structure that contains NIEM association members. For example, I have:

Code: Select all

<nc:Activity s:id="Activity1">
    <nc:ActivityCategoryText>My new activity</nc:ActivityCategoryText>
.
.
</nc:Activity>
<nc:Activity s:id="Activity2">
    <nc:ActivityCategoryText>My second activity</nc:ActivityCategoryText>
.
.
</nc:Activity>
<nc:Subject s:id="Person1">
    <mine:PersonStatus>Approved</mine:PersonStatus>
.
.
</nc:Subject>
<nc:Subject s:id="Person2">
    <mine:PersonStatus>Dismissed</mine:PersonStatus>
.
.
</nc:Subject>
.
.
.

<mine:ActivitySubjectAssociation>
            <nc:Activity s:ref="Activity1"/>
            <nc:Subject s:ref="Person1"/>
</mine:AcitvitySubjectAssociation>
[<mine:ActivitySubjectAssociation>
            <nc:Activity s:ref="Activity1"/>
            <nc:Subject s:ref="Person2"/>
</mine:AcitvitySubjectAssociation>


And need to check if the Activity is of some nc:ActivityCategoryText, the Subjects associated with that activity has a given mine:PersonStatus code.

How would I loop through the associations and referance entries across the associations?
tavy
Posts: 122

Re: Schematron rules for NIEM association elements

Fri Jan 13, 2017 6:03 pm

Hello,

I don't understand exactly what you want to check. Maybe you can give me some real examples, how many persons can be associated with an activity, or how many activities can be associated with a person, maybe you have a schema for the XML file.

If you want to check for example if the persons of a specific activity are approved, you can create a rule like this:

Code: Select all

<sch:pattern>
        <sch:rule context="nc:Activities/nc:Activity">
            <sch:let name="id" value="@s:id"/>
            <sch:let name="personId" value="//mine:ActivitySubjectAssociation[nc:Activity/@s:ref = $id]/nc:Subject/@s:ref"/>
            <sch:let name="person" value="//nc:Subject[@s:id=$personId]"/>
            <sch:assert test="if (nc:ActivityCategoryText/text()='My new activity') then $person/mine:PersonStatus/text() ='Approved' else true()">
                Persons associated with this activity should be approved</sch:assert>
           
        </sch:rule>
    </sch:pattern>

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
cjhukill
Posts: 11

Re: Schematron rules for NIEM association elements

Wed Jan 18, 2017 2:28 pm

Sorry for the late reply. Yes, there will be several of both with different text and status. Need to check PersonStatus for 'Approved' or 'Pending'. My issue was getting the PersonID for all the people associated with a specific ActivityID. Can you explain the structure of getting the PersonID in your example?

Thanks so much for all your help!!!
tavy
Posts: 122

Re: Schematron rules for NIEM association elements

Thu Jan 19, 2017 10:31 am

Hello,

If you have a rule with the context set on the "nc:Activity" element, you can execute an XPath expression that will get all activity associations that have the current activity id "//mine:ActivitySubjectAssociation[nc:Activity/@s:ref = $id]". Then from the association you can access the person id using "/nc:Subject/@s:ref" XPath expression.

Code: Select all

<sch:let name="allPersonIds" value="//mine:ActivitySubjectAssociation[nc:Activity/@s:ref = $id]/nc:Subject/@s:ref"/>


Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
cjhukill
Posts: 11

Re: Schematron rules for NIEM association elements

Thu Jan 19, 2017 8:52 pm

Great! I understand. I have added that rule to my set and seems to be working great. Now off to more testing...

Thank you so much for all your help!!!!

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests