Isolate a specific node and ancestors

onlinemarketz2

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 breadcrumbs.How can I isolate only a specific node with \[code\]@id=$id\[/code\] and his ancestors, to build breadcrumbs up to current page from home?Resulting html should be, for a node ad the third nested level:\[code\]<ul> <li><a href="http://stackoverflow.com/questions/12420294/url1.php">Home</a></li> <li><a href="http://stackoverflow.com/questions/12420294/urla.php">Some child of home</a></li> <li><a href="http://stackoverflow.com/questions/12420294/urlb.php">Some grandchild of home</a></li> <li><a class='active' href="http://stackoverflow.com/questions/12420294/urlc.php">Current page which is child of the above</a></li></url>\[/code\]
 
Back
Top