Yes this is possible. It took me a while to find some documentation when I first tried to do it within a plugin. You need to look at the docs for the template class instead of the plugin API. Specifically the section for variable pairs.
You need to create a multidimensional array that contains the different rows for your variable pair. Here's some relevant sections from a plugin I wrote that displays a gallery that's created using matrix, assets and playa. I've simplified it a lot but hopefully you will get the idea.
In the first bit of code I've done a database query to get my assets and then looped through the results to create the variable pair array:
$assets_array = array();
if ($assets_query->num_rows() != 0)
{
// loop through assets and create an array indexed with the associated matrix row_id
foreach ($assets_query->result() as $row)
{
$assets_array[$row->row_id][] = array('image_url' => $this->EE->typography->parse_file_paths($row->file_path),
'alt_text' => $row->alt_text
);
}
}
When I create the single vars for the main tag, I loop through the query result for the matrix rows and create a var that contains the assets array.
foreach ($matrix_query->result() as $row)
{
$vars[] = array(
'row_id' => $row->row_id,
'entry_id' => $row->entry_id,
'image' => $assets_array[$row->row_id],
);
}
$this->return_data = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $vars);
Then in my template I can do something like this:
{exp:sp_gallery}
{image}<img src="{image_url}" alt="{alt_text}"{/image}
{/exp:sp_gallery}
Hope that helps.