[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XML structure to HTML unordered list
Hey all,
I'm struggling to figure out a good way to transform a XML structure into a HTML unordered list. So far the solution I've come up with looks like this: Sample index.xml file <?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xsl" href="index.xsl"?> <root_element> <item id="1"> desc 1 <item id="11"> desc 11 </item> <item id="12"> desc 12 <item id="121"> desc 121 <item id="1211"> desc 1211 <item id="12111"> desc 122111 <item id="1211111"> desc 1211111 <item id="12111111"> desc 12111111 </item> <item id="12111112"> desc 12111112 </item> </item> </item> </item> </item> </item> </item> <item id="2"> desc 2 <item id="21"> desc 21 </item> <item id="22"> desc 22 <item id="221"> desc 221 </item> <item id="222"> desc 222 </item> </item> <item id="23"> desc 23 </item> </item> </root_element> And here's my index.xsl file <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" omit-xml-declaration="yes"/> <xsl:template match="root_element"> <html> <body> <xsl:call-template name="unordered-list"> <xsl:with-param name="items" select="item"/> </xsl:call-template> </body> </html> </xsl:template> <xsl:template name="unordered-list"> <xsl:param name="items" select="/.."/> <ul> <xsl:for-each select="$items"> <li> <xsl:value-of select="text()"/> <xsl:if test="item"> <xsl:call-template name="unordered-list"> <xsl:with-param name="items" select="item"/> </xsl:call-template> </xsl:if> </li> </xsl:for-each> </ul> </xsl:template> </xsl:stylesheet> The above produces what I want, and it seems quite solid. But is there perhaps another (better?) way to solve this task? I'm limited to XSLT 1.0. Sincerely, Thomas
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|