How can I transform data into html

You can render any data using a template file:


theme_render_template($template_file, $vars);

This is a base drupal function.

You can get a path to a template file in your module as


$template_file = 
drupal_get_path(
   'module', 'your_module_name') . '/your-tempalte.tpl.php';

The $vars can be any data structure


<table>
    <tr>
              <td><?php echo t('To');?>:</td>
              <td><?php echo $variable1;?></td>
            </tr>
              <td><?php echo render($form);?></td>
    </tr>
</table>

function test_function_convert_data_to_html_via_template()
{
      $vocabularies = taxonomy_vocabulary_get_names();
      $vid = $vocabularies['my_vocabulary']->vid;
      $terms = taxonomy_get_tree($vid, 0);
      $template_file = 
            drupal_get_path('module', 
              'Your_module') . '/your-template.tpl.php';
      dpm($terms);
      $vars['typeOfTermsArray'] = $terms;
      return theme_render_template($template_file, $vars);
}

<p>
Hello world. This demonstrates templates.
</p>
<?php foreach ($typeOfTermsArray as $term) : ?>
  <p>
  <?php echo $term->name; ?>
  </p>
<?php endforeach; ?>

The data must be passed using an associative array. The name of the association becomes a variable name in the template file.

In render arrays one can pass a theme function to render that data. One can also use a template file instead of a theme function.