Isolate a specific node and his ancestors or 1st level children

Annouseseency

New Member
I have an XML like:\[code\]<menu> <node id="home" url="url1.php"> <label>Homepage</label> <node id="user" url="url2.php"><label>User profile</label></node> <node id="help" url="url3.php"><label>Help page</label></node> ... </node></menu>\[/code\]Its used to generate a menu, the XML has \[code\]node\[/code\] tags nested at any level under the first "home" \[code\]node\[/code\].I pass a parameter called \[code\]$id\[/code\] with PHP which gives the current active menu item.(The \[code\]<label>\[/code\] is in a separate tag and not as attribute because I've many labels for localization, actual xml is like \[code\]<label lang='en'>...</label><label lang='it'>...</label>\[/code\])The idea is to use various XSLs to generate main menu, breadcrumbs, section titles (top menu).For the main menu I've managed to do this:\[code\]<xsl:template match="menu"> <xsl:apply-templates select="node" /></xsl:template><xsl:template match="//node"> <ul> <li> <a> <xsl:if test="@id=$id"> <xsl:attribute name='class'>active</xsl:attribute> </xsl:if> <xsl:attribute name='href'> <xsl:value-of select="@url" /> </xsl:attribute> <xsl:value-of select="label"/> </a> <xsl:if test="count(child::*)>0"> <xsl:apply-templates select="node" /> </xsl:if> </li> </ul> </xsl:template></xsl:stylesheet>\[/code\]And it works. But I'm stuck with the other two. [*]How can I isolate a specific node with id=$id and his ancestors, to build breadcrumbs up to current page from home?[*]How can I get only the first level children of "home", setting \[code\]class="active"\[/code\] if the first-level child is ancestor of node with id=$id?In both cases HTML should be similar (\[code\]<ul>\[/code\] with only first level of \[code\]<li>\[/code\]s, each one of those with a link \[code\]<a>\[/code\])
 
Back
Top