What I want to achieve is not so simple but I'll try my best to make myself clear. I have the following document:
\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{makeidx}
\makeindex
\begin{document}
\section*{List}
The index \texttt{testindex} appears in these locations: \printindex
\section{First}
\textcolor{red}{The index does not appear here.}
\clearpage
\subsection{First.First}
\textcolor{green}{The index appears here.\index{testindex}}
\clearpage
\section{Second}
\textcolor{red}{The index does not appear here.}
\clearpage
\subsection{Second.First}
\textcolor{red}{The index does not appear here.}
\clearpage
\subsubsection{Second.First.First}
\textcolor{green}{The index appears here.\index{testindex}}
\clearpage
\section{Third}
\textcolor{green}{The index appears here.\index{testindex}}
\clearpage
\end{document}
The \printindex command produces this output:

What I want is a comma-separated list of the sections/subsections/subsubsections (whatever is more specific) of all occurrences and I want all of these values to be links to the specified locations, i.e. when I click on 1.1 that the document will jump to First.First.
I generated the desired output (without the link behaviour) for a better understanding:

Can anyone help me?
and patch the index command to write the current section number to this list.
– cmhughes Jan 21 '18 at 13:08