<?xml-stylesheet type="text/xsl" href="/exist/rest/db/apps/xsltforms/xsltforms.xsl"?><?xsltforms-options debug="yes"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>CSV Survey</title>
        <xf:model xmlns:xf="http://www.w3.org/2002/xforms">
            <xf:instance id="survey">
                <survey xmlns="">
                    <person output-label="Personal Data" state="ok">
                        <first_name input-label="First Name" type="Text"/>
                        <last_name input-label="Last Name" type="Text"/>
                        <email input-label="Email" type="Text"/>
                    </person>
                    <job_evaluation output-label="Job Evaluation">
                        <department input-label="Which of the following best describes the department you work in?" type="Departments"/>
                        <department_other input-label="Your department:" type="Text"/>
                        <satisfaction input-label="How satisfied are you with your position?" type="Satisfaction"/>
                    </job_evaluation>
                    <teamwork output-label="Teamwork">
                        <encourage input-label="Does your department encourage teamwork?" type="Agrees"/>
                        <spirit input-label="How satisfied are you with the spirit of teamwork within your company?" type="Satisfaction"/>
                    </teamwork>
                </survey>
            </xf:instance>
            <xf:instance id="variables">
                <variables xmlns="">
                    <state/>
                </variables>
            </xf:instance>
            <xf:bind nodeset="person/first_name" required="true()"/>
            <xf:bind nodeset="person/last_name" required="true()"/>
            <xf:bind nodeset="person/email" type="email" required="true()"/>
            <xf:bind nodeset="job_evaluation/department_other" relevant="../department = 'other'"/>
            <xf:instance id="sets">
                <sets xmlns="">
                    <set type="Departments">
                        <item label="Customer Service" value="cs"/>
                        <item label="Finance/Accounting" value="finance"/>
                        <item label="Sales/Marketing" value="sales"/>
                        <item label="Human Resources" value="hr"/>
                        <item label="Other" value="other"/>
                    </set>
                    <set type="Satisfaction">
                        <item label="Not satisfied or dissatisfied" value="-1"/>
                        <item label="Somewhat satisfied" value="0"/>
                        <item label="Very satisfied" value="1"/>
                    </set>
                    <set type="Agrees">
                        <item label="Disagree" value="-1"/>
                        <item label="Neutral" value="0"/>
                        <item label="Agree" value="1"/>
                    </set>
                </sets>
            </xf:instance>
            <xf:instance id="flatten">
                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
                    <xsl:output method="xml"/>
                    <xsl:template match="/">
                        <data xmlns="">
                            <item>
                                <xsl:apply-templates select="descendant::*[not(*)]"/>
                            </item>
                        </data>
                    </xsl:template>
                    <xsl:template match="*">
                        <xsl:copy>
                            <xsl:value-of select="."/>
                        </xsl:copy>
                    </xsl:template>
                </xsl:stylesheet>
            </xf:instance>
            <xf:instance id="precsv">
                <data xmlns=""/>
            </xf:instance>
            <xf:bind nodeset="instance('precsv')/item/first_name" required="true()"/>
            <xf:bind nodeset="instance('precsv')/item/last_name" required="true()"/>
            <xf:bind nodeset="instance('precsv')/item/email" required="true()"/>
            <xf:submission id="s01" ref="instance('precsv')" mediatype="text/csv" method="post" replace="all" show="new" separator="," resource="xsltforms/echo.php">
                <xf:message xmlns:ev="http://www.w3.org/2001/xml-events" level="modeless" ev:event="xforms-submit-error">Your answers have not been registered. Please <xf:output value="choose(event('error-type')='validation-error','check fields contents.','try again later.')"/>
                </xf:message>
                <xf:setvalue xmlns:ev="http://www.w3.org/2001/xml-events" ev:event="xforms-submit-done" ref="instance('variables')/state" value="'registered'"/>
            </xf:submission>
        </xf:model>
        <style type="text/css">
    body {
        margin-left:2em;
        margin-top:2em;
        font-size:110%;
    }
    input {
        margin-left:1em;
        margin-right:1em;
    }
    #xsltforms_console {
        margin-top:3em;
        padding-top:1em;
        font-size:75%;
        }
    iframe {
        display:none;
    }
    #xsltforms_debug {
        padding-bottom:1em;
    }
    
    .btn {
    -moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    -moz-border-right-colors: none;
    -moz-border-top-colors: none;
    background-color: #F5F5F5;
    background-image: linear-gradient(to bottom, #FFFFFF, #E6E6E6);
    background-repeat: repeat-x;
    border-bottom-color: #A2A2A2;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
    border-bottom-style: solid;
    border-bottom-width: 1px;
    border-image-outset: 0 0 0 0;
    border-image-repeat: stretch stretch;
    border-image-slice: 100% 100% 100% 100%;
    border-image-source: none;
    border-image-width: 1 1 1 1;
    border-left-color-ltr-source: physical;
    border-left-color-rtl-source: physical;
    border-left-color-value: #BBBBBB;
    border-left-style-ltr-source: physical;
    border-left-style-rtl-source: physical;
    border-left-style-value: solid;
    border-left-width-ltr-source: physical;
    border-left-width-rtl-source: physical;
    border-left-width-value: 1px;
    border-right-color-ltr-source: physical;
    border-right-color-rtl-source: physical;
    border-right-color-value: #BBBBBB;
    border-right-style-ltr-source: physical;
    border-right-style-rtl-source: physical;
    border-right-style-value: solid;
    border-right-width-ltr-source: physical;
    border-right-width-rtl-source: physical;
    border-right-width-value: 1px;
    border-top-color: #BBBBBB;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    border-top-style: solid;
    border-top-width: 1px;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
    color: #333333;
    cursor: pointer;
    display: inline-block;
    font-size: 14px;
    line-height: 20px;
    margin-top:1em;
    margin-bottom:1em;
    padding-bottom: 4px;
    padding-left: 12px;
    padding-right: 12px;
    padding-top: 4px;
    text-align: center;
    text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
    vertical-align: middle;
    }
    .btn:hover, .btn:active, .btn.active, .btn.disabled, .btn[disabled] {
    background-color: #E6E6E6;
    color: #333333;
    }
    .btn:active, .btn.active {
    }
    .btn:first-child {
    }
    .btn:hover {
    -moz-text-blink: none;
    -moz-text-decoration-color: -moz-use-text-color;
    -moz-text-decoration-line: none;
    -moz-text-decoration-style: solid;
    background-color: #E6E6E6;
    background-position: 0 -15px;
    color: #333333;
    transition-delay: 0s;
    transition-duration: 0.1s;
    transition-property: background-position;
    transition-timing-function: linear;
    }
    .btn:focus {
    outline-color: #333333;
    outline-offset: -2px;
    outline-style: dotted;
    outline-width: thin;
    }
    .btn.active, .btn:active {
    background-color: #E6E6E6;
    background-image: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
    outline-color: -moz-use-text-color;
    outline-style: none;
    outline-width: 0;
    }
    a {
    text-decoration:none;
    color: #0088CC;
    }
    a:hover {
    -moz-text-blink: none;
    -moz-text-decoration-color: -moz-use-text-color;
    -moz-text-decoration-line: underline;
    -moz-text-decoration-style: solid;
    color: #005580;
    }
    .xforms-value {margin-left:1em;}
    .description {
        color: gray;
        margin-top:2em;
        font-size: 80%;}
</style>
    </head>
    <body>
        <div class="source">
            <div class="toolbar">
                <a class="btn" href="/exist/apps/eXide/index.html?open=/db/apps/XSLTForms-Demo/data/survey.xml" target="eXide" data-type="XML" title="Opens the form in eXide.">Open form in eXide</a>
            </div>
        </div>
        <h1>CSV Survey</h1>
        <xf:group xmlns:xf="http://www.w3.org/2002/xforms" ref=".[instance('variables')/state = 'ok']">
            <p>Thank you for answering!</p>
        </xf:group>
        <xf:group xmlns:xf="http://www.w3.org/2002/xforms" ref=".[instance('variables')/state = 'registered']">
            <p>Your answers have been successfully registered.</p>
        </xf:group>
        <xf:repeat xmlns:xf="http://www.w3.org/2002/xforms" nodeset="*[@state = instance('variables')/state]">
            <xf:group ref=".">
                <fieldset>
                    <legend>
                        <xf:output value="@output-label"/>
                    </legend>
                    <xf:repeat nodeset="*">
                        <xf:select1 ref=".[@type != 'Text']" appearance="full">
                            <xf:label>
                                <br/>
                                <xf:output ref="@input-label"/>
                            </xf:label>
                            <xf:itemset nodeset="instance('sets')/set[@type = current()/@type]/item">
                                <xf:label ref="@label"/>
                                <xf:value ref="@value"/>
                            </xf:itemset>
                        </xf:select1>
                        <xf:input ref=".[@type = 'Text']" incremental="true">
                            <xf:label>
                                <br/>
                                <xf:output value="@input-label"/>&#160;</xf:label>
                        </xf:input>
                    </xf:repeat>
                </fieldset>
            </xf:group>
        </xf:repeat>
        <xf:trigger xmlns:xf="http://www.w3.org/2002/xforms" ref=".[instance('variables')/state = '']">
            <xf:label>Finish this survey</xf:label>
            <xf:setvalue xmlns:ev="http://www.w3.org/2001/xml-events" ev:event="DOMActivate" ref="instance('variables')/state" value="'ok'"/>
        </xf:trigger>
        <xf:trigger xmlns:xf="http://www.w3.org/2002/xforms" ref=".[instance('variables')/state = 'ok']">
            <xf:label>Send us your answers</xf:label>
            <xf:action xmlns:ev="http://www.w3.org/2001/xml-events" ev:event="DOMActivate">
                <xf:setnode ref="instance('precsv')" outer="transform(instance('survey'),serialize(instance('flatten')),true())"/>
                <xf:send submission="s01"/>
            </xf:action>
        </xf:trigger>
        <div xmlns="" class="description">
            <description/>
        </div>
    </body>
</html>