<?xml version="1.0" encoding="UTF-8"?>
<sch:pattern id="ISM-ID-00141" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
    <sch:p id="ruleText">
        [ISM-ID-00141][Error] If ISM-NSI-EO-APPLIES and 
            1. ISM-RESOURCE-ELEMENT attribute declassException does not have a value of "25X1-human"
            AND
            2. ISM-RESOURCE-ELEMENT attribute declassDate is not specified
            AND
            3. ISM-RESOURCE-ELEMENT attribute declassEvent is not specified
            AND
            4. ISM-RESOURCE-ELEMENT attribute atomicEnergyMarkings is not specified
               with a value of [RD] or [FRD]
            
        Human Readable: declassDate or declassEvent are required unless 25X1-human, RD, or FRD is specified.
    </sch:p>
    <sch:p id="codeDesc">
        If the current Classified National Security Information Executive Order
        does not apply to the document then the rule does not apply
        and we return true. If the resourceElement has attribute declassException specified 
        with a value of [25X1-human] then the rule does not apply and we return true. If 
        the resourceElement has attribute atomicEnergyMarkings specified with a value containing
        [RD] or [FRD] then the rule does not apply and we return true. Otherwise, we make sure
        that the resourceElement has attribute declassDate specified or attribute declassEvent 
        specified.
    </sch:p>
    <sch:rule context="//*[generate-id(.) = generate-id($ISM_RESOURCE_ELEMENT)]">
        <sch:assert 
            id="ISM-00141" 
            test="
            if(not($ISM_NSI_EO_APPLIES)) then true() else 
                if(matches(./@ism:declassException, '25X1-human')) then true() else
                    if(
                        sum(
                            for $each in tokenize(./@ism:atomicEnergyMarkings, ' ') return
                                if(matches($each, '^F?RD-?.*$'))
                                    then 1
                                    else 0
                        )>0
                    ) then true()
                    else (./@ism:declassDate or ./@ism:declassEvent)
            " 
            flag="error">
            [ISM-ID-00141][Error] declassDate or declassEvent are required unless 25X1-human, RD, or FRD is specified.
        </sch:assert>
    </sch:rule>
</sch:pattern>