Author
Using XSL to display XML
Angela lewis
Ranch Hand
Joined: Mar 01, 2004
Posts: 100
I am very new to xml. I am trying to display xml using xsl but with no success. Here's my XML file <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <doc> <title> <string lang="en">A</string> <string lang="fr">B</string> </title> <body> <val> <string lang="en">C</string> <string lang="fr">D</string> </val> <val> <string lang="en">E</string> <string lang="fr">F</string> </val> </body> </doc> and this is my xsl <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2><xsl:value-of select="doc/title"/></h2> <table border="1"> <xsl:for-each select="doc/body/val"> <tr> <td><xsl:value-of select="string"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> But this xsl only displays the first string element value but not the second one. Please help
Balaji Loganathan
author and deputy
Bartender
Joined: Jul 13, 2001
Posts: 3150
posted Sep 29, 2004 07:45:00
0
Hi, Try this...
Spritle Software Blogs
Balaji Loganathan
author and deputy
Bartender
Joined: Jul 13, 2001
Posts: 3150
posted Sep 29, 2004 07:47:00
0
Or this... (kinda hardcoded)
Angela lewis
Ranch Hand
Joined: Mar 01, 2004
Posts: 100
thank u so much
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted Sep 29, 2004 19:39:00
0
Hi Angela, I found (after the inital learning curve) is much more clear cut and easier to maintain when you separate the template elements. Instead of using a loop let the XLST processor figure out how to go. It is more typing in the beginning... AND give you a good headstart in pattern matching. I haven't taken care of the header (your title element) which should be inside the table? So this is my take: So have fun! :-) stw
subject: Using XSL to display XML