\documentclass{article}
\usepackage{xsim}

\DeclareExerciseCollection{foo-easy}
\DeclareExerciseCollection{foo-medium}
\DeclareExerciseTagging{difficulty}

\usepackage{filecontents,lipsum}
\begin{filecontents*}{foo.tex}
\begin{exercise}[difficulty=easy,points=1]
  foo one \lipsum[4]
\end{exercise}
\begin{solution}
  foo one \lipsum[4]
\end{solution}
\begin{exercise}[difficulty=medium,points=1]
  foo two \lipsum[4]
\end{exercise}
\begin{solution}
  foo two \lipsum[4]
\end{solution}
\begin{exercise}[difficulty=easy,points=1]
  foo three \lipsum[4]
\end{exercise}
\begin{solution}
  foo three \lipsum[4]
\end{solution}
\end{filecontents*}

\begin{document}

\begin{exercise}
  outside before
\end{exercise}

\collectexercises{foo-easy}
\xsimsetup{difficulty=easy}
\input{foo.tex}
\collectexercisesstop{foo-easy}
% collection `foo-easy' now contains all exercises of file `foo.tex' tagged
% with `difficulty=easy'

\collectexercises{foo-medium}
\xsimsetup{difficulty=medium}
\input{foo.tex}
\collectexercisesstop{foo-medium}
% collection `foo-medium' now contains all exercises of file `foo.tex'
% tagged with `difficulty=medium'

\section{Easy}
\printcollection{foo-easy}

\section{Medium}
\printcollection{foo-medium}

\printsolutions[difficulty=medium]

\section{All Exercises and Their Solutions Again, in Order of Appearance}

\printcollection[print=both]{all exercises}

\end{document}
