How to display only those taxonomy terms that have content? Can this be done with the help of relationships or contextual filters?
If you create a view to show terms, you can create a relationship for "Taxonomy term: Content with term". This will allow you to access all the nodes referencing each term.
In the configuration screen for the relationship, you can check the "Require this relationship" checkbox (see screenshot below). Like that, terms that are not referenced by any node will not be displayed.