Nested Nodes Unravelling
Nested Nodes Unravelling
(OP)
I have a very simple XML:
I need to turn it into an HTML list with <ul> and <li> tags. However, being very much a novice, I am struggling to cope with the fact that some of the <nav> tags in the source contain other <nav> tags as child nodes.
The following works in part for the parent nodes when set to match 'nav' and for the child nodes when set to match 'nav/nav'.
Stuck in a never ending cycle of file copying.
<?xml version="1.0" encoding="UTF-8"?> <nav title="Containerized IP Office J100 Series Phone User Guide" homepage="Introduction.html"> <nav title="Introduction" href="Introduction.html"> <nav title="Important Safety Information" href="Important_Safety_Information.html"/> <nav title="J129 Telephone" href="J129_Telephone.html"/> <nav title="J139 Telephone" href="J139_Telephone.html"/> <nav title="Appearance Buttons" href="Appearance_Buttons.html"> <nav title="Call Appearance Buttons" href="Call_Appearance_Buttons.html"/> <nav title="Line Appearance Buttons" href="Line_Appearance_Buttons.html"/> </nav> <nav title="Programmable Feature Buttons" href="Feature_Buttons.html"/> <nav title="Status Display" href="Status_Display.html"> <nav title="Status Icons" href="Status_Icons.html"/> <nav title="Status Letters" href="Status_Letters.html"/> </nav> <nav title="Icons" href="Icons.html"/> <nav title="The Phone Stand" href="The_Phone_Stand.html"/> </nav> ...
I need to turn it into an HTML list with <ul> and <li> tags. However, being very much a novice, I am struggling to cope with the fact that some of the <nav> tags in the source contain other <nav> tags as child nodes.
The following works in part for the parent nodes when set to match 'nav' and for the child nodes when set to match 'nav/nav'.
<?xml version="1.0" encoding="UTF-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> <xsl:template match="/"> <hmtl><head><title>Test</title></head> <ul><xsl:apply-templates/></ul> </hmtl> </xsl:template> <xsl:template match="nav"> <xsl:for-each select="nav"> <li><p><xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute><xsl:value-of select="@title"/> </xsl:element></p></li> </xsl:for-each> </xsl:template> </xsl:transform>
Stuck in a never ending cycle of file copying.
RE: Nested Nodes Unravelling
The unordered lists begin at the first "nav" of the branch. The first descendant and the next sibling are given the responsibility to grow the list deeper and wider, as needed:
CODE --> XSLT
Resulting in:
RE: Nested Nodes Unravelling
Looking after a documentation website with material coming from a variety of authoring tools, I've become competent with HTML, RSS, PHP, Javascript, etc. But I suspect with XSL I'm about to discover many of my past tagged content reuse scenarios could have been much easier and powerful.
Stuck in a never ending cycle of file copying.