Thinly slice the onions. In a large heavy based saucepan heat the oil and cook the onions until soft, but not too browned. Add the salt, pepper and rosemary sprigs and cover and cook gently for a further 15 minutes until very soft.
Remove the lid and add the vinegar and sugar. Stir well. Bring to a gentle boil and cook uncovered for a further 15-20 minutes until the liquid has been absorbed and the mixture is soft and sticky. Stir frequently to prevent burning.
Pick out the stalks of rosemary and transfer the mixture into a clean, dry, sterilised jar. Cool and seal. Store in the refrigerator.
The marmalade will keep for two weeks and makes a lovely gift.