Redmine#3279: nth() function now data container aware

Rebased #1056

Please merge, it's been reviewed thoroughly.