<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="menu.xsl"?> <root> <item id="1" idParent="0" link="#" title=" 1"/> <item id="2" idParent="1" link="#" title=" 2"/> <item id="3" idParent="1" link="#" title=" 3"/> <item id="4" idParent="2" link="#" title=" 4"/> <item id="5" idParent="2" link="#" title=" 5"/> <item id="6" idParent="1" link="#" title=" 6"/> <item id="7" idParent="6" link="#" title=" 7"/> <item id="8" idParent="6" link="#" title=" 8"/> <item id="9" idParent="0" link="#" title=" 9"/> </root>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- --> <xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" doctype-system="about:legacy-compat"/> <!-- --> <xsl:template match="/"> <html lang="ru"> <head> <title> </title> </head> <body> <h1> </h1> <ul> <xsl:apply-templates select="/root/item[@idParent=0]"/> </ul> </body> </html> </xsl:template> <!-- --> <xsl:template match="/root/item"> <xsl:variable name="id" select="@id"/> <!-- --> <li> <a href="{@link}"> <xsl:value-of select="@title"/> </a> <!-- --> <xsl:if test="/root/item[@idParent=$id]"> <ul> <xsl:apply-templates select="/root/item[@idParent=$id]"/> </ul> </xsl:if> </li> </xsl:template> </xsl:stylesheet>
Source: https://habr.com/ru/post/138997/
All Articles