protected static function replaceTokensInAttribute(DOMAttr $attribute, $regexp, $fn)
	{
		$attrValue = preg_replace_callback(
			$regexp,
			function ($m) use ($fn, $attribute)
			{
				$replacement = $fn($m, $attribute);
				if ($replacement[0] === 'expression' || $replacement[0] === 'passthrough')
				{
					// Use the node's text content as the default expression
					$replacement[] = '.';

					return '{' . $replacement[1] . '}';
				}
				else
				{
					return $replacement[1];
				}
			},
			$attribute->value
		);
		$attribute->value = htmlspecialchars($attrValue, ENT_COMPAT, 'UTF-8');
	}