Page 1 of 1

Schematron rules for NIEM association elements

Posted: Fri Jan 13, 2017 12:41 am
by cjhukill
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?

Re: Schematron rules for NIEM association elements

Posted: Fri Jan 13, 2017 6:03 pm
by tavy
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

Re: Schematron rules for NIEM association elements

Posted: Wed Jan 18, 2017 2:28 pm
by cjhukill
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!!!

Re: Schematron rules for NIEM association elements

Posted: Thu Jan 19, 2017 10:31 am
by tavy
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

Re: Schematron rules for NIEM association elements

Posted: Thu Jan 19, 2017 8:52 pm
by cjhukill
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!!!!