XRX/大型 XForms 生成器
外观
< XRX
您希望能够使用 REST 服务生成大型 XForms 以进行大型表单的性能测试。主要测试项目是表单加载后表单变为“就绪”需要多长时间。
我们将使用 XQuery 创建 XForms 文件。此 XQuery 将接收一个 URL 参数,该参数包含要生成的元素数量。XForms 将为每个计数包含一个输入字段和两个 select1 字段。每个输入控件将在模型中拥有自己的实例。
<root>
<input1>input 1</input1>
<input2>input 2</input2>
<country-code1>country-code 1</country-code1>
<country-code2>country-code 2</country-code2>
<state-code1>state-code 1</state-code1>
<state-code2>state-code 2</state-code2>
</root>
xquery version "1.0";
let $count := xs:positiveInteger(request:get-parameter('count', '20'))
return
<root>
{for $counter in (1 to $count)
return
element {concat('input', $counter)} {concat('input ', $counter)}
}
{for $counter in (1 to $count)
return
element {concat('country-code', $counter)} {concat('country-code ', $counter)}
}
{for $counter in (1 to $count)
return
element {concat('state-code', $counter)} {concat('state-code ', $counter)}
}
</root>
for $counter in (1 to $input-count)
return
(<xf:input ref="input{$counter}">
<xf:label>Input {$counter}:</xf:label>
</xf:input>,
<br/>)
for $counter in (1 to $select1-count)
return
(<xf:select1 ref="country-code{$counter}">
<xf:label>Country {$counter}:</xf:label>
<xf:itemset nodeset="instance('code-tables')/code-table[name='country-code']/items/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
</xf:itemset>
</xf:select1>,
<br/>
)
代码表存储在名为“code-tables.xml”的静态 XML 文件中。格式如下
<code-tables>
<code-table>
<name>country-code</name>
<items>
<item>
<label>Select a Country...</label>
<value/>
</item>
<item>
<label>Afghanistan</label>
<value>af</value>
</item>
<item>
<label>Albania</label>
<value>al</value>
</item>
...etc....
</items>
</code-table>
</code-tables>
xquery version "1.0";
(: Default function and element declarations :)
declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/1999/xhtml";
declare namespace xf="http://www.w3.org/2002/xforms";
declare namespace ev="http://www.w3.org/2001/xml-events";
declare option exist:serialize "method=xhtml media-type=text/xml indent=no process-xsl-pi=no";
let $count := xs:positiveInteger(request:get-parameter('count', '20'))
let $input-count := $count
let $select1-count := $count
let $style :=
<style language="text/css">
<![CDATA[
@namespace xf url("http://www.w3.org/2002/xforms");
body {
font-family: Helvetica, Arial, sans-serif;
}
.block-form xf|label {
width: 10ex;
font-weight: bold;
width: 10ex;
display: inline-block;
text-align: right;
}
]]>
</style>
let $model :=
<xf:model>
<xf:instance id="save-data" src="instance.xq?count={$input-count}"/>
<xf:instance id="code-tables" src="code-tables.xml" xmlns=""/>
</xf:model>
let $content :=
<div class="content">
{
for $counter in (1 to $input-count)
return
(<xf:input ref="input{$counter}">
<xf:label>Input {$counter}:</xf:label>
</xf:input>,
<br/>)
}
{
for $counter in (1 to $select1-count)
return
(<xf:select1 ref="country-code{$counter}">
<xf:label>Country {$counter}:</xf:label>
<xf:itemset nodeset="instance('code-tables')/code-table[name='country-code']/items/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
</xf:itemset>
</xf:select1>,
<br/>
)
}
{
for $counter in (1 to $select1-count)
return
(<xf:select1 ref="state-code{$counter}">
<xf:label>State {$counter}:</xf:label>
<xf:itemset nodeset="instance('code-tables')/code-table[name='us-state-code']/items/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
</xf:itemset>
</xf:select1>,
<br/>
)
}
</div>
let $form :=
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events">
<head>
<title>Test Form</title>
{ $style }
{ $model }
</head>
<body>
<div class="container">
<div class="inner">
<h2>Test Form</h2>
{ $content }
</div>
</div>
</body>
</html>
let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="/rest/db/xforms/xsltforms-new/xsltforms.xsl"'}
let $debug := processing-instruction xsltforms-options {'debug="yes"'}
return ($xslt-pi, $debug, $form)
许多大型表单使用大型代码表。本示例使用两个大型代码表。一个是世界各国列表,另一个是美国州代码列表。