When using the DOM api to add xsl commands to your stylesheet dynamically, be sure to use createElementNS() rather than createElement() otherwise the XSLTProcessor will not recognise these DOM nodes.
Eg:
$xsl->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:element');