You're right that this is a grouping problem. First thing is to establish whether you're using 1.0 or 2.0.
Try to tackle some simpler grouping problems first, and build up to this one. For example, see if you can do it in the case where "fonctions" is a separate attribute on its own.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference