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);
	}
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);
	}
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 ) ; }
Replace parts of a template that match given regexp

Treats attribute values as plain text. Replacements within XPath expression is unsupported.
The callback must return an array with two elements. The first must be either of 'expression',
'literal' or 'passthrough', and the second element depends on the first.

- 'expression' indicates that the replacement must be treated as an XPath expression such as
'@foo', which must be passed as the second element.

- 'literal' indicates a literal (plain text) replacement, passed as its second element.

- 'passthrough' indicates that the replacement should the tag's content. It works differently
whether it is inside an attribute's value or a text node. Within an attribute's value, the
replacement will be the text content of the tag. Within a text node, the replacement
becomes an <xsl:apply-templates/> node. A second optional argument can be passed to be used
as its @select node-set.

@param  string   $template Original template
@param  string   $regexp   Regexp for matching parts that need replacement
@param  callback $fn       Callback used to get the replacement
@return string             Processed template
Replace parts of a template that match given regexp