I try to display the results of a survey where students of 2 different classes could choose their favorite subject.
In the result table I find Surname, Name, ClassID, Subject.
The data in the file ff14.txt
I'm using looks like this:
ClassID; Schueler_Name; Schueler_Vorname; Subject
5a; Stiner; Markus; Big Band
3c; Meier; Stefan; Latein
5b; Muggli; Elena; Instrument
3b; Strang; Flurin; Band
3b; Nomer; Ulrike; Big Band
Now I'd like to order the results by class and then display all the students in this class with their chosen favorite subject.
I've done something similar before using nlatexdb
, where I used a nested construction. However, when I try to apply the same code to datatool
I get a very different result.
In the PDF the class is not grouped but displayed 27 times (as many as there are students in the class). So the resulting PDF consists of 27 tables each containing 27 students. But what I would like to have is 2 tables (there are 2 classes) with all the student in the corresponding class.
My MWE:
\documentclass[12pt]{article}
\usepackage{babel, fixltx2e}
\usepackage{xltxtra}
\usepackage{xunicode}
\usepackage{float}
\usepackage{datatool}
\DTLsetseparator{;}
\DTLloaddb{anmeldungen}{ff14.txt}
\begin{document}
\DTLforeach{anmeldungen}{\class=ClassID}{
\subsection*{Klasse \class}
\begin{tabular}{ll} \hline
\textbf{Name} & \textbf{Vorname}
\DTLforeach{anmeldungen}{\fn=Schueler_Vorname, \ln=Schueler_Name}{\DTLiffirstrow{\\ \hline}{\\ }
\ln & \fn } \\ \hline \hline
\end{tabular}
\begin{flushright}
\DTLsavelastrowcount{\n}
\n\ Anmeldungen.
\end{flushright}
}
foreach entry {build table with each entry}
so you will get n tables with n rows.