/**
  * Helper to prepare form for step 2.
  *
  * Contains a drop down menu created for tag; other options are hidden
  * inputs.
  */
 private function _elementForm($xmlImportSession)
 {
     // Get first level nodes of first file in order to choose document name.
     $fileList = $xmlImportSession->file_list;
     $format = $xmlImportSession->format;
     $stylesheet = $xmlImportSession->stylesheet;
     // TODO Add the root element name, because some formats use it.
     reset($fileList);
     $filepath = key($fileList);
     try {
         $doc = $this->_domXmlLoad($filepath);
     } catch (Exception $e) {
         $this->_helper->flashMessenger($e->getMessage(), 'error');
         return;
     }
     foreach ($doc->childNodes as $primary) {
         $elementSet = $this->cycleNodes($primary, $elementList = array(), $number = 0);
     }
     require_once "Zend/Form/Element.php";
     $form = new Omeka_Form();
     $form->setAttrib('id', 'xmlimport')->setAction('send')->setMethod('post');
     // Check available record elements inside xml file. This is used only
     // with generic sheets. The tag will not be used in other cases.
     // Check if the node is defined in the list of parameters.
     $parametersAdded = trim($stylesheetParameters) == '' ? array() : array_values(array_map('trim', explode('><', trim($stylesheetParameters, ' <>'))));
     foreach ($parametersAdded as $value) {
         if (strpos($value, '=') !== FALSE) {
             list($paramName, $paramValue) = explode('=', $value);
             if ($paramName != '') {
                 $parameters[trim($paramName)] = trim($paramValue);
             }
         }
     }
     // Automatic import via Omeka CSV Report.
     if ($format == 'Report') {
         $tagNameElement = new Zend_Form_Element_Hidden('tag_name');
         $tagNameElement->setValue('item');
     } elseif (count($elementSet) == 1) {
         reset($elementSet);
         $tagNameElement = new Zend_Form_Element_Hidden('tag_name');
         $tagNameElement->setValue(key($elementSet));
     } elseif (substr(basename($stylesheet), 0, 19) !== 'xml_import_generic_') {
         reset($elementSet);
         $tagNameElement = new Zend_Form_Element_Hidden('tag_name');
         $tagNameElement->setValue(key($elementSet));
     } elseif (isset($parameters['node'])) {
         reset($elementSet);
         $tagNameElement = new Zend_Form_Element_Hidden('tag_name');
         $tagNameElement->setValue($parameters['node']);
     } else {
         $tagNameElement = new Zend_Form_Element_Select('tag_name');
         $tagNameElement->setLabel('Tag Name')->addMultiOptions($elementSet);
     }
     $form->addElement($tagNameElement);
     $fileListElement = new Zend_Form_Element_Hidden('file_list');
     $fileListElement->setValue(serialize($fileList));
     $form->addElement($fileListElement);
     foreach (array('csv_filename' => $xmlImportSession->csv_filename, 'file_import' => $xmlImportSession->file_import, 'xml_folder' => $xmlImportSession->xml_folder, 'format_filename' => $xmlImportSession->format_filename, 'format' => $format, 'action' => $xmlImportSession->action, 'identifier_field' => $xmlImportSession->identifier_field, 'item_type_id' => $xmlImportSession->item_type_id, 'collection_id' => $xmlImportSession->collection_id, 'records_are_public' => $xmlImportSession->public, 'records_are_featured' => $xmlImportSession->featured, 'elements_are_html' => $xmlImportSession->html_elements, 'create_collections' => $xmlImportSession->create_collections, 'contains_extra_data' => $xmlImportSession->contains_extra_data, 'column_delimiter' => $xmlImportSession->column_delimiter, 'enclosure' => $xmlImportSession->enclosure, 'element_delimiter' => $xmlImportSession->element_delimiter, 'tag_delimiter' => $xmlImportSession->tag_delimiter, 'file_delimiter' => $xmlImportSession->file_delimiter, 'stylesheet' => $stylesheet, 'stylesheet_parameters' => $xmlImportSession->stylesheet_parameters) as $name => $value) {
         $element = new Zend_Form_Element_Hidden($name);
         $element->setValue($value);
         $form->addElement($element);
     }
     // Submit button.
     $form->addElement('submit', 'submit');
     $submitElement = $form->getElement('submit');
     $submitElement->setLabel(__('Next'));
     return $form;
 }