Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - How to transform recusrive XML data with XSL? >Thread Next - Re: How to transform recusrive XML data with XSL? Re: How to transform recusrive XML data with XSL?To: NULL Date: 3/11/2005 1:59:00 PM David Bowey wrote: > I've the following "recursive" XML file... > > ###### XML FILE ###### > > <?xml version="1.0" encoding="utf-8" ?> > <Nodes> > <Node> > <text>Parent 1</text> > <Nodes> > <Node> > <text>Child 1</text> > <Nodes> > <Node> > <text>Grandchild 1</text> > </Node> > </Nodes> > </Node> > <Node> > <text>Child 2</text> > </Node> > </Nodes> > </Node> > <Node> > <text>Parent 1</text> > <Nodes> > <Node> > <text>Child 1</text> > <Nodes> > <Node> > <text>Grandchild 1</text> > </Node> > </Nodes> > </Node> > <Node> > <text>Child 2</text> > </Node> > </Nodes> > </Node> > </Nodes> > > ###### END XML FILE ###### > > How do I transform this XML data into XHTML bulleted list using XSL? That is rather easy with XSLT, you simply write templates for each of the different elements you have above creating the needed XHTML elements (e.g. <ul>, <li>) and then recursively with apply-templates process the remaining nodes: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0"> <xsl:output method="xml" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" omit-xml-declaration="yes" /> <xsl:template match="/"> <html xml:lang="en" lang="en"> <head> <title>list</title> </head> <body> <xsl:apply-templates /> </body> </html> </xsl:template> <xsl:template match="Nodes"> <ul> <xsl:apply-templates /> </ul> </xsl:template> <xsl:template match="Node"> <li> <xsl:apply-templates /> </li> </xsl:template> <xsl:template match="text"> <span><xsl:value-of select="." /></span> </xsl:template> </xsl:stylesheet> -- Martin Honnen http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
