XForms/案例验证
外观
< XForms
您想要检查一个字段是大写还是小写。
注意:这似乎在 FireFox 或 XSLTForms 中不起作用。
我们将使用绑定约束。
<xf:bind nodeset="UpperCaseText" type="xs:string" constraint=" . eq translate(., 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') "/>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<head>
<title>Case Test</title>
<style type="text/css">
<![CDATA[
body {
font-family: Helvetica, sans-serif;
}
]]>
</style>
<xf:model>
<xf:instance xmlns="">
<data>
<LowerCaseText>abc</LowerCaseText>
<UpperCaseText>ABC</UpperCaseText>
</data>
</xf:instance>
<xf:bind nodeset="UpperCaseText" type="xs:string"
constraint="
. eq translate(., 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') "/>
<!-- compare the string to the lower-case version. If they are the same we pass -->
<xf:bind nodeset="LowerCaseText" type="xs:string"
constraint="
. eq translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') "/>
</xf:model>
</head>
<body>
<h1>Case Test</h1>
<p>To pass this test the form must warn the user if they enter an invalid string.
The XForms alert message
must also be visible.</p>
<xf:input ref="LowerCaseText" incremental="true">
<xf:label>Lower Case String:</xf:label>
<xf:alert>The string must contain lowercase only.</xf:alert>
</xf:input>
<br/>
<xf:input ref="UpperCaseText" incremental="true">
<xf:label>Upper Case String:</xf:label>
<xf:alert>The string must contain uppercase only.</xf:alert>
</xf:input>
<br/>
</body>
</html>