Skip to content

Instantly share code, notes, and snippets.

@jtuttas
Created May 11, 2013 11:17
Show Gist options
  • Save jtuttas/5559681 to your computer and use it in GitHub Desktop.
Save jtuttas/5559681 to your computer and use it in GitHub Desktop.
Zeugnisnoten Durchschnitt
cls
[xml]$a = Get-Content ("schulklasse_zeugnis.xml")
$n = $a.SelectNodes("//pupil")
foreach ($p in $n) {
$sum=0
$z=$p.zeugnis.FirstChild
do {
if ($z.Name -ne "fehlzeiten") {
$sum=$sum+$z.InnerText
}
}
while ($z=$z.NextSibling)
$p.zeugnis.SetAttribute("average",$sum/4)
}
$a.Save("schulklasse_zeugnis_neu.xml")
<klasse>
<pupil name="Andreas" gender="male" age="22">
<zeugnis>
<fehlzeiten>
<gesamt>8</gesamt>
<entschuldigt>7</entschuldigt>
</fehlzeiten>
<lf1>2</lf1>
<lf2>3</lf2>
<lf3>2</lf3>
<lf4>1</lf4>
</zeugnis>
</pupil>
<pupil name="Nina" gender="female" age="20">
<zeugnis>
<fehlzeiten>
<gesamt>1</gesamt>
<entschuldigt>1</entschuldigt>
</fehlzeiten>
<lf1>1</lf1>
<lf2>2</lf2>
<lf3>1</lf3>
<lf4>2</lf4>
</zeugnis>
</pupil>
</klasse>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment