- From: Costello, Roger L. <costello@mitre.org>
- Date: Sat, 23 May 2009 14:06:17 -0400
- To: "'xproc-dev@w3.org'" <xproc-dev@w3.org>
Hi Folks, In the book Business Rules Applied, Barbara von Halle categorizes the various kinds of rules: 1. Constraint rules 2. Computation rules 3. Inference rules 4. Action enabler rules XProc can express all these rules! CONSTRAINT RULES Here is an example of a constraint rule: A customer must not have more than 10 open orders at one time. XML Schema, RELAX NG, NVDL, and Schematron can express constraint rules. Consider this XML instance: <customer id="John_Doe"> <open-orders>12</open-orders> </customer> The result of executing the constraint rule on the XML instance is a report such as this: Error!!! The customer with id John_Doe has more open orders than allowed. COMPUTATION RULES Here is an example of a computation rule: The total-amount-due for an order is computed as the sum of the line-item amount(s) for the order plus tax. The result of executing a computation rule is the creation of a new piece of information, produced by a computation. XSLT can express computation rules. Consider this XML instance: <order id="A430334930"> <line-item>12.99</line-item> <line-item>6.35</line-item> <line-item>21.00</line-item> <line-item>15.99</line-item> <tax>2.81</tax> </order> The result of executing the computation rule on the XML instance is this new information: total-amount-due: 59.14 This new information may then be added to the order: <order id="A430334930"> <line-item>12.99</line-item> <line-item>6.35</line-item> <line-item>21.00</line-item> <line-item>15.99</line-item> <tax>2.81</tax> <total-amount-due>59.14</total-amount-due> </order> The computation rule can be expressed using this XSLT: <xsl:variable name="total-amount-due" select="sum(order/(line-item,tax))" /> INFERENCE RULES Here is an example of an inference rule: If a customer has no outstanding invoices, then the customer is of preferred status. The result of executing an inference rule is to establish a new fact. XSLT can be used to express inference rules. Consider this XML instance: <customer id="John_Doe"> <outstanding-invoices>0</outstanding-invoices> </customer> The result of executing the inference rule is to establish this new fact: preferred-customer: John-Doe This new fact may then be added to a list of preferred customers: <preferred-customers> <preferred-customer id="Sally_Smith" /> <preferred-customer id="Tom_Jones" /> <preferred-customer id="Nancy_Drew" /> <preferred-customer id="John_Doe" /> </preferred-customers> The inference rule can be expressed using this XSLT: <xsl:variable name="preferred-customer" select="customer[outstanding-invoices=0]/@id" /> ACTION ENABLER RULES Here is an example of an action enabler rule: If a customer order is valid, then initiate the Place Order process. The result of executing an action enabler rule is to initiate an event, message or other activity. XProc can be used to express action enabler rules. Here is how the action enabler rule can be expressed using XProc: <p:input port="source"> <p:document href="customer-order.xml" /> </p:input> <p:try> <p:group> <px:validate-order /> </p:group> <p:catch> <p:identity> <p:input port="source"> <p:inline> <c:result>Invalid Order</c:result> </p:inline> </p:input> </p:identity> </p:catch> </p:try> <p:choose> <p:when test="not(c:result='Invalid Order')"> <px:place-order /> </p:when> </p:choose> The XProc pipeline inputs the customer order and validates it; if the order is valid it initiates the place-order process. XPROC STEPS ARE DIVERSE An XProc pipeline contains steps which can perform XML Schema validation, RELAX NG validation, Schematron validation, or XSLT transformation. And XProc can initiate new processes. Thus, an XProc pipeline can express all of the different kinds of rules - constraint rules, computation rules, inference rules and activity enabler rules. LESSON LEARNED 1. I spend lots of time obsessing over how to express constraints, and what schema language should be used. But now I see that constraint rules are just one of four kinds of rules. 2. Constraint rules can be expressed using XML Schema, RELAX NG, NVDL, and Schematron. 3. Computation rules can be expressed using XSLT. 4. Inference rules can be expressed using XSLT. 5. Action Enabler rules can be expressed using XProc. 6. The execution of a constraint rule may result in a report describing the violation of a constraint. 7. The execution of either a computation or inference rule may result in new information. 8. The execution of an activity enabler may result in new activity. 9. XProc has steps for XML Schema validation, RELAX NG validation, Schematron validation, and XSLT transformation. Thus, {constraint, computation, inference, action enabler} rules can be expressed using XProc pipelines. /Roger
Received on Saturday, 23 May 2009 18:06:56 UTC