What I want to achieve is to include a count of
line_items per order, and to include it as say
total_line_items in the output.
I don't know how to a.) get the count per order,
I think you'll find what you need at http://api.rubyonrails.org/ in the methods pane (lower left) under 'count'.
b.) how to include in the output.
This will depend on what, exactly, you want the output to look like. to_xml is very limited. Except in very unusual cases, I personally don't think it's a great idea to couple an app's output so tightly to the application's internal data representation. YMMV. to_xml may or may not give you the flexibility you need. Builder is so incredibly simple to use that it's definitely worth looking at right from the 'git go' IMHO. The output you decide on could / probably will have an impact on your decision re: how exactly to approach getting the counts you're looking for.