public static function replaceTokens($template, $regexp, $fn)
	{
		$dom   = TemplateLoader::load($template);
		$xpath = new DOMXPath($dom);
		foreach ($xpath->query('//@*') as $attribute)
		{
			self::replaceTokensInAttribute($attribute, $regexp, $fn);
		}
		foreach ($xpath->query('//text()') as $node)
		{
			self::replaceTokensInText($node, $regexp, $fn);
		}

		return TemplateLoader::save($dom);
	}