This is the first in a series of code example articles that will be posted to give NIEM developers a head start in using Schematron. This example will show how to perform a test across multiple branches or nodes of a typical NIEM schema as law enforcement officer is a role played by a person in NIEM schemas. Take the following example XML code:
<ns:SomeDocument> <j:Citation> <j:CitationIssuingOfficial> <nc:RoleOfPersonReference s:ref="P1"/> </j:CitationIssuingOfficial> </j:Citation> <nc:Person s:id="P1"> <nc:PersonName><nc:PersonSurName>Smith</nc:PersonSurName></nc:PersonName> </nc:Person> </ns:SomeDocument>
One way in which to test for the existence of a last name is to match the ID with the officer's REF and test to be sure the string length is greater than 1 as shown in the following example (using XSLT2 & ISO Schematron):
<pattern id="eOfficerData"> <let name="sOfficerRef" value="ns:SomeDocument/j:Citation/ j:CitationIssuingOfficial/nc:RoleOfPersonReference/@s:ref"/> <rule context="ns:SomeDocument/nc:Person"> <report test="@s:id = $sOfficerRef and string-length(nc:PersonName/nc:PersonSurName) < 1"> Officers last name must be provided. </report> </rule> </pattern>
In theory the same test can be done using the XQuery id()
function however use of the id
function is HIGHLY dependent on the parser's capabilities.
No comments:
Post a Comment