#/* Du format 2 au format 1 des Noms-Notes, inversion de UnVersDeux.pl */

use strict;
use warnings;
use XML::DOM;

sub transformer ($) { #Document -> Document
	my ($doc) = @_;
	my $depart = $doc->getDocumentElement();
	my $rac = $depart->getNodeName();
	
	my $res = XML::DOM::Document->new();
	my $r_rac = $res->createElement($rac);
	$res->appendChild($r_rac);
	
	my @les_eleves = $depart->getElementsByTagName("eleve");
	foreach my $l_eleve ( @les_eleves  ){ # foreach marche avec NodeList !

	#lecture
	my $les_enfants = $l_eleve->getChildNodes();
	my $son_nom = $les_enfants->item(0);
	my $sa_note = $les_enfants->item(1);
	
	my $le_nom = $son_nom->getFirstChild()->getData();
	my $la_note = $sa_note->getFirstChild()->getData();
	
	#construction
	my $r_eleve = $res->createElement("eleve");
	$r_rac->appendChild($r_eleve);
	$r_eleve->setAttribute("prenom", $le_prenom);
	$r_eleve->setAttribute("nom", $le_nom);
	$r_eleve->setAttribute("note", $la_note);
  }
			
	return $res;
}# transformer

sub DeuxVersUn($$){
	my ($fichIn, $fichOut) = @_;
	my $parseur = XML::DOM::Parser->new();
	my $doc = $parseur->parsefile($fichIn);
	open(SORTIE, ">$fichOut");
	
	my $res = transformer($doc);
	print(SORTIE $res->toString());
	
}#DeuxVersUn

DeuxVersUn($ARGV[0], $ARGV[1]);