Moved the call to clone the template node to the start of the next() method

to overcome Segmentation fault in php-fpm 5.3.10 which appears to dislike using insertBefore with a node that already exists within the template

-- Iain Dooley
Revert "Moved the call to clone the template node to the start of the next() method"

This reverts commit a1a989fac6c7843eaa4236aecca9c07c4e06cd68.
setValue method would throw error if content empty (null) when `$asHTML = true`
integrated Sani's change: 'setValue method throws error if content empty (null) when `$asHTML = true`'
Fix #12: Store resolved XPaths to reduce overhead

This doubles the speed of `repeat` loops.
With big thanks to sani for pointing this out.

P.S. F* GIT. F* GIT SO MUCH. This buggered up so badly. Sorry for the
no-doubt spam of commit messages.
Some error handling to deal with invalid XPath expressions and invalid HTML.
Remember to handle the thrown exception in your code when you insert HTML!