FUNCTION theme_convert_menu($menusource){
$themed_menu = new DOMDocument();
@$themed_menu->loadXML($menusource);
$templateSource = <<<TEMPLATESOURCE
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each SELECT="node()|@*[not(.='')]">
<xsl:copy SELECT="node()">
<xsl:copy-of SELECT="@*[not(.='')]"/>
<xsl:apply-templates />
</xsl:copy>
</xsl:for-each>
</xsl:template>
<xsl:template match="a">
<a>
<xsl:copy-of SELECT="@*[not(.='')]"/>
<span>
<xsl:copy-of SELECT="node()"/>
</span>
</a>
</xsl:template>
<xsl:template match="ul">
<ul>
<xsl:copy-of SELECT="@*[not(.='')]"/>
<xsl:copy-of SELECT="node()"/>
</ul>
</xsl:template>
<xsl:template match="ul/li/ul/li">
<li>
<xsl:copy-of SELECT="node()">
<xsl:apply-templates SELECT="(ul|li|a)"/>
</xsl:copy-of>
</li>
</xsl:template>
<xsl:template match="li">
<xsl:copy SELECT="node()|@*[not(.='')]">
<xsl:copy-of SELECT="@*[not(.='')]"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="ul[@id='nav']/li/ul">
<div class="subnav">
<span class="top-bg"> </span>
<div class="bg">
<div>
<xsl:copy SELECT="node()|@*[not(.='')]">
<xsl:apply-templates/>
</xsl:copy>
</div>
</div>
<span class="bottom-bg"> </span>
</div>
</xsl:template>
<xsl:template match="ul[@id='nav']/li//ul/li">
<xsl:copy SELECT="node()">
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="ul[@id='nav']/li//ul/li/ul">
<xsl:copy SELECT="node()">
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
TEMPLATESOURCE;
$xpath = new domXPath($themed_menu);
$xpathQuery = $xpath->query("/ul/li");
$topItemCount = 0;
foreach($xpathQuery AS $topItem){
IF(++$topItemCount > 5)
$topItem->appendChild($themed_menu->createAttribute('class'))->appendChild($themed_menu->createTextNode('absolut'));
}unset($topItem,$topItemCount,$xpath,$xpathQuery);
$stylesheet = new DOMDocument();
$stylesheet->loadXML($templateSource);
unset($templateSource);
$xsl = new XSLTProcessor();
$xsl->importStyleSheet($stylesheet);
unset($stylesheet);
$temp = new DOMDocument();
@$temp->loadXML($xsl->transformToXML($themed_menu));
unset($xsl);
$Menu = stripDOMoutPut($temp);
RETURN $Menu;
}
IN my tpl...
diamond_convert_menu($menu)