I'm not sure where you're having difficulty, or exactly what your requirements are, so it's not easy to provide specific help.
However, please don't think of XSLT in terms of "write the start tag, then write the content, then write the end tag". XSLT creates trees, which are then serialized. The first thing you do is to create an HTML element node on the tree, then you create other nodes as its children. So creating a start tag and end tag are not two separate operations, they are a single indivisible act. I mention this because if you think of them as separate actions you get into all kinds of programming muddles.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference