Skip to content Skip to sidebar Skip to footer

Turn Xml Data To Html Table With Xslt

I need to be able to turn a flat xml data sets into html tables, and I'm having trouble finding syntax examples that will fit my need. I would like to use one stylesheet that can c

Solution 1:

If you did not find examples of transforming XML to HTML with XSLT, then you didn't look very hard. That's one of its primary motivations. Anyway, this should get you started:

<?xml version="1.0" encoding="utf-8"?><xsl:transformversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:outputomit-xml-declaration="yes"indent="yes"/><xsl:templatematch="node()|@*"/><xsl:templatematch="/Services"><html><head><title>XSLT example</title></head><body><xsl:apply-templates/></body></html></xsl:template><xsl:templatematch="Service"><xsl:apply-templates/></xsl:template><xsl:templatematch="Operations"><table><thead><tr><td>Name</td><td>Description</td><td>Type</td></tr></thead><tbody><xsl:apply-templates/></tbody></table></xsl:template><xsl:templatematch="Operaion"><!-- [sic] --><xsl:variablename="service"select="ancestor::Service"/><tr><td><xsl:value-ofselect="$service/Name"/></td><td><xsl:value-ofselect="Name"/></td><td><xsl:value-ofselect="$service/Category"/></td></tr></xsl:template></xsl:transform>

Output on your (corrected) document (it was missing end tags):

<html><head><title>XSLT example</title></head><body><table><thead><tr><td>Name</td><td>Description</td><td>Type</td></tr></thead><tbody><tr><td>ServiceName</td><td>HelloWorld</td><td>CatName</td></tr><tr><td>ServiceName</td><td>OP2name</td><td>CatName</td></tr><tr><td>ServiceName</td><td>Op3Name</td><td>CatName</td></tr></tbody></table></body></html>

Post a Comment for "Turn Xml Data To Html Table With Xslt"