Shell scripting

The given file consists of two tags i.e., <free-energy> and <position> tag. I want the output like this. The tag <length> is not required to consider.

(General format of output)

free-energy no.
 
first position no - second position no
third position no - fourth position no
------
------
Free-energy no
First position no - second position no
Third position no -fourth position no.

Output for the given file is

-25.40
 
9 - 20
25 - 127
-24.80 
2 - 13
 
------------------------------------------------
 
<structure analysis-ids="UNAFold">
<!-- Start of folding 1 for sequence 1 ************************ -->
<model id="_1.1">
<model-info>
<free-energy>-25.40</free-energy>
</model-info>
<base-id>
<position>9</position>
</base-id>
</base-id-5p>
<base-id-3p>
<base-id>
<position>20</position>
</base-id>
</base-id-3p>
<length>4</length>
</helix>
     <base-id>
     <position>25</position>
     </base-id>
     </base-id-5p>
 
     <position>127</position>
     </base-id>
     </base-id-3p>
         <!-- End of folding 1 for sequence 1 ************************ -->
     <!-- Start of folding 2 for sequence 1 ************************ -->
<model id="_1.2">
<model-info>
<free-energy>-24.80</free-energy>
</model-info>
<str-annotation>
<base-id>
<position>2</position>
</base-id>
</base-id-5p>
<position>13</position>

PLS. HELP ME TO WRITE A SHELL SCRIPT FOR THIS WHICH HELPS A LOT IN BIOINFORMATICS RESEARCH. THANKS IN ADVANCE.

#!/bin/bash
while IFS='<>' read Null Tag Val Null
do
case $Tag in
free-energy)
echo $Val
Pos=0 ;;
position)
((Pos++))
((Pos%2)) && echo -n "$Val" || echo " - $Val" ;;
esac
done <file

Here's an equivalent awk, just in case:

awk -F'[<>]*' '$2=="free-energy"{print $3}$2=="position"{printf "%s%s",$3,(++i%2)?" - ":RS}' infile