<?xml version="1.0" encoding="UTF-8"?>
<% number_of_tests = 0 %>
<% number_of_failures = 0 %>
<% @results.each { |a| number_of_tests += a[:number_of_tests] } %>
<% @results.each { |a| number_of_failures += a[:number_of_failures] } %>

<testsuites tests="<%= number_of_tests %>" failures="<%= number_of_failures %>">
  <% @results.each do |testsuite| %>
    <testsuite name=<%= testsuite[:test_name].encode(:xml => :attr) %> tests="<%= testsuite[:number_of_tests] %>" failures="<%= testsuite[:number_of_failures] %>" time="<%= testsuite[:duration] %>">
      <% testsuite[:tests].each do |test| %>
        <testcase classname=<%= test[:test_group].encode(:xml => :attr) %> name=<%= test[:name].encode(:xml => :attr) %> time="<%= test[:duration] %>">
          <% (test[:failures] || []).each do |failure| %>
            <failure message=<%= failure[:failure_message].encode(:xml => :attr) %>>
            </failure>
          <% end %>
        </testcase>
      <% end %>
    </testsuite>
  <% end %>
</testsuites>

<?xml version="1.0" encoding="UTF-8"?>
<% number_of_tests = 0 %>
<% number_of_failures = 0 %>
<% @results.each { |a| number_of_tests += a[:number_of_tests] } %>
<% @results.each { |a| number_of_failures += a[:number_of_failures] } %>

<testsuites tests="<%= number_of_tests %>" failures="<%= number_of_failures %>">
  <% @results.each do |testsuite| %>
    <testsuite name=<%= (testsuite[:target_name] == nil ? testsuite[:test_name] : testsuite[:target_name]).encode(:xml => :attr) %> tests="<%= testsuite[:number_of_tests] %>" failures="<%= testsuite[:number_of_failures] %>" time="<%= testsuite[:duration] %>">
      <% testsuite[:tests].each do |test| %>
        <testcase classname=<%= test[:test_group].encode(:xml => :attr) %> name=<%= test[:name].encode(:xml => :attr) %> time="<%= test[:duration] %>">
          <% (test[:failures] || []).each do |failure| %>
            <failure message=<%= failure[:failure_message].encode(:xml => :attr) %>>
            </failure>
          <% end %>
        </testcase>
      <% end %>
    </testsuite>
  <% end %>
</testsuites>

Test for target_name, if it is not there, use test_name instead.
Test for target_name, if it is not there, use test_name instead.
