Performance Tweak 7: Don't build up XML nodes

One of the remaining slow points in our layer application was the need to build an XML node every time we applied a layer. As we have around a dozen layers and several thousand nodes, this was a bit of a bottleneck.

This patch applies the layers and avoids building up the XML by simply excluding text between angle brackets.

Also applied PEP8 fixes.

This is a ~50% improvement of page performance (using current master as a baseline).