protected function normalizeAttributes(PHPTAL_Dom_Element $element)
    {
        parent::normalizeAttributes($element);

        $attrs_by_qname = array();
        foreach ($element->getAttributeNodes() as $attrnode) {
            // safe, as there can't be two attrs with same qname
            $attrs_by_qname[$attrnode->getQualifiedName()] = $attrnode;
        }

	if (count($attrs_by_qname) > 1) {
		uksort($attrs_by_qname, array($this, 'compareQNames'));
		$element->setAttributeNodes(array_values($attrs_by_qname));
	}
    }