Databases Reference
In-Depth Information
Date validation
Using Schematron is also an excellent method of validating dates based on the
current time. For example, we need to check that the expiry date for the credit
card is not in the past.
To do this, we need to check that the expiry year of the CreditCard is greater than the
current year, or that the expiry year of the CreditCard equals the current year, and
the current month is less than or equal to the expiry month of the card.
To do this, we could write the following test:
cmn:expiryYear>xp20:year-from-dateTime(xp20:current-dateTime())or
(cmn:expiryYear=xp20:year-from-dateTime(xp20:current-dateTime())and
cmn:expiryMonth>=xp20:month-from-dateTime(xp20:current-dateTime()))
Element present
Another requirement is to check whether an element is present or not. We can do this
with XML Schema by defining an element as being mandatory. However, whether
an element is optional or mandatory may well be based on values in other fields.
For example, if we had made securityNo optional within our schema definition,
but we wanted to make it mandatory for American Express, we could write the
following rule:
<rulecontext="//cmn:creditCard[cmn:cardType='AmericanExpress']">
<asserttest="cmn:securityNo">
SecurityNomustbespecified
</assert>
</rule>
Note that this will only check to see if the element is present in the XML instance. It
doesn't actually check if it actually contains a value. The simplest way to check this is
to use the string-length function, as shown in the following code snippet:
<rulecontext="//cmn:creditCard[cmn:cardType='AmericanExpress']">
<asserttest="cmn:securityNoandstring-length(cmn:securityNo)>0">
SecurityNomustbespecified
</assert>
</rule>
 
Search WWH ::




Custom Search