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)
許多大型表單使用大型程式碼表。本示例使用兩個大型程式碼表。一個是世界各國列表,另一個是美國州程式碼列表。