That's a vast question - whole books have been written on the subject. Sorry, all I can suggest is to do some reading.
I wrote the Java and XML chapter of the latest edition of Wrox Professional XML, so I would recommend that as a starting point.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference