You haven't made it clear quite how flexible the input structure is, or what kind of output you want. I would personally be very inclined to start by transforming this to a more straightforward XML representation:
<env>
<Email_Details>
<Account code="A">
<UserName>User A</UserName>
<SMPTServer>Server A</SMTPServer>
<Account>
<Account code="B">
<UserName>User B</UserName>
<SMPTServer>Server B</SMTPServer>
<Account>
</Email_Details>
</env>
and then everything would start to seem much simpler.
However, whatever the output you're aiming for, recursive structures are best dealt with by a stylesheet that does recursive descent using apply-templates. Just write a rule for each kind of element, and in that rule do what you need to do with that element, then call apply-templates to process its children. I can't tell you what these rules should look like (or even how many there should be - it's not clear whether attributes at different levels are processed the same way) without knowing your desired output.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference