[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
How_To_XML_Display_XML_In_HTML_Table_XSLT
How to display XML elements in HTML table using ?XSLT?
Create an XML document with one root element <books> and a number of child elements <book>. Each child element will also have two child elements: <title> and <location.
The example shows how to bind text between the <title> and <location> elements to an HMTL table.
Create the XSL stylesheet.
Output:
To bind XML elements to the HTML table, the <xsl:for-each> XSL template must appear before the table row tag to make sure that a new row is created for each <book> element.
The <xsl:value-of> template will output each selected child elements' text in a separate table cell.
Back to XML FAQ
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
How_To_XML_Display_XML_In_HTML_Table_XSLT
How to display XML elements in HTML table using ?XSLT?
Create an XML document with one root element <books> and a number of child elements <book>. Each child element will also have two child elements: <title> and <location.
The example shows how to bind text between the <title> and <location> elements to an HMTL table.
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="books04.xsl"?> <books> <book> <title>OpenGL Programming Guide Fourth Edition</title> <location>107</location> </book> <book> <title>Curves and Surfaces for CAGD: A Practical Guide</title> <location>116</location> </book> <book> <title>An Introduction to NURBS: With Historical Perspective</title> <location>120</location> </book> <book> <title>NURBS: From Projective Geometry to Practical Use</title> <location>126</location> </book> </books>
Create the XSL stylesheet.
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="UTF-8"/> <xsl:template match="/"> <html> <head><title>Books</title> </head> <body> <table width="100%" border="1"> <THEAD> <TR> <TD width="35%"><B>Title</B></TD> <TD width="15%"><B>Location</B></TD> </TR> </THEAD> <TBODY> <xsl:for-each select="books/book"> <TR> <TD width="35%"><xsl:value-of select="title" /></TD> <TD width="15%"><xsl:value-of select="location" /></TD> </TR> </xsl:for-each> </TBODY> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Output:
Title Location OpenGL Programming Guide Fourth Edition 107 Curves and Surfaces for CAGD: A Practical Guide 116 An Introduction to NURBS: With Historical Perspective 120 NURBS: From Projective Geometry to Practical Use 126
To bind XML elements to the HTML table, the <xsl:for-each> XSL template must appear before the table row tag to make sure that a new row is created for each <book> element.
The <xsl:value-of> template will output each selected child elements' text in a separate table cell.
Back to XML FAQ
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
