XRX/Large XForms Generator

< XRX

Motivation edit

You want to be able to generate large XForms using a REST service for doing performance tests for large forms. The primary item being tested is how long does the form take to become "ready" after the form is loaded.

Method edit

We will use an XQuery to create XForms files. This XQuery will take a single URL parameter that has a count of the number of elements it will generate. The XForms will have one input field and two select1 fields for each count. Each input control will have its own instance in the model.

Sample of Instance in the model. edit

<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>

Instance Generator edit

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>

Autogeneration of Input Fields edit

for $counter in (1 to $input-count)
   return
      (<xf:input ref="input{$counter}">
          <xf:label>Input {$counter}:</xf:label>
          </xf:input>,
      <br/>)

Autogeneration of Select1 Fields edit

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/>
     )

The code tables are stored in a static XML file called "code-tables.xml". The format is as follows:

<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>

Source Code edit

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)

Sample Code Tables edit

Many large forms use large code tables. This example uses two large code tables. One is a list of all the countries in the world and another is a list of all US State Codes.

Sample Usage edit

Sample Output edit