<?xml version="1.0"?>
<!--
Ruleset contains one single rule:
IF         <LoanPurpose>.Type = Refinance
            AND NOT EXISTS <REOProperty> with SubjectIndicator=”Y”
THEN   Set Action - DataValidation = Fail

Reference XML schema is AUS_v2_4.xsd, aka "mismo"
-->
<RuleSet>
   <contains>
      <Rule>
         <ruleVariable>
            <Forall>
               <declare><Var>?loanApplication</Var></declare>
               <pattern>
                  <NonMonNot>
                     <formula>
                        <Exists>
                           <declare><Var>?reoProperty</Var></declare>
                           <formula>
                              <Frame>
                                 <object><Member>
                                            <object><Var>?loanApplication</Var></object>
                                            <class><Const type="rif:iri">mismo:AUS_LOAN_APPLICATION_Type</Const></class>
                                         </Member>
                                 </object>
                                 <slotKey><Const type="rif:iri">REO_PROPERTY</Const></slotKey>
                                 <slotValue><Frame>
                                               <object><Var>?reoProperty</Var></object>
                                               <slotKey><Const type="rif:iri">@_SubjectIndicator</Const></slotKey>
                                               <slotValue><Const type="mismo:AUS_MISMOIndicatorType">Y</Const></slotValue>
                                            </Frame>
                                 </slotValue>
                              </Frame>
                           </formula>
                        </Exists>
                     </formula>
                  </NonMonNot>
               </pattern>
            </Forall>
         </ruleVariable>
         <if>
            <Exists>
               <declare><Var>?loanPurpose</Var></declare>
               <formula>
                  <Frame>
                     <object><Var>?loanApplication</Var></object>
                     <slotKey><Const type="rif:iri">LOAN_PURPOSE</Const></slotKey>
                     <slotValue><Frame>
                                   <object><Var>?loanPurpose</Var></object>
                                   <slotKey><Const type="rif:iri">@_Type</Const></slotKey>
                                   <slotValue><Const type="mismo:AUS_LoanPurposeTypeEnumerated">Refinance</Const></slotValue>
                                </Frame>
                     </slotValue>
                  </Frame>
               </formula>
            </Exists>
         </if>
         <then>
            <!-- 
The ACTION part is not yet clearly specified;
and, the rule could trigger different actions, anyway, depending how a data validation error is defined
So, for the sake of the example, I just assumed that there was a _DataValidation attribute to the LOAN_APPLICATION element
            -->
            <Assert>
               <Frame>
                  <object><Var>?loanApplication</Var></object>
                  <slotKey><Const type="rif:iri">@_DataValidation</Const></slotKey>
                  <slotValue><Const type="mismo:AUS_MISMODataValidationResultType">fail</Const></slotValue>
               </Frame>
            </Assert>
         </then>
      </Rule>
   </contains>
</RuleSet>            
