xml - XSL How do I create Dynamic Table Row -



xml - XSL How do I create Dynamic Table Row -

my xml looks this

<catalog> <cd> <title>empire burlesque</title> <artist>bob dylan</artist> <country>usa</country> <company>columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>hide heart</title> <artist>bonnie tyler</artist> <country>uk</country> <company>cbs records</company> <price>9.90</price> <year>1988</year> </cd> </catalog>

what want accomplish html table number of rows dynamic, example:

table should this:

table header <tr> <td>title</td> <td>empire burlesque</td> </tr> <tr> <td>artist</td> <td>bob dylan</td> </tr> <tr> <td>country</td> <td>usa</td> </tr>

goes on nodes available cd.

all want able loop number of nodes available under <cd> , generate individual <tr> each node in html output. dont have utilize <xsl:value-of select> particular xml node name.

can help me understand basic of part? thanks.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="catalog"> <table> <xsl:apply-templates select="cd/*"/> </table> </xsl:template> <xsl:template match="cd/*"> <tr> <td> <xsl:value-of select="name()"/> </td> <td> <xsl:value-of select="."/> </td> </tr> </xsl:template> </xsl:stylesheet>

output:

<table> <tr> <td>title</td> <td>empire burlesque</td> </tr> <tr> <td>artist</td> <td>bob dylan</td> </tr> <tr> <td>country</td> <td>usa</td> </tr> <tr> <td>company</td> <td>columbia</td> </tr> <tr> <td>price</td> <td>10.90</td> </tr> <tr> <td>year</td> <td>1985</td> </tr> <tr> <td>title</td> <td>hide heart</td> </tr> <tr> <td>artist</td> <td>bonnie tyler</td> </tr> <tr> <td>country</td> <td>uk</td> </tr> <tr> <td>company</td> <td>cbs records</td> </tr> <tr> <td>price</td> <td>9.90</td> </tr> <tr> <td>year</td> <td>1988</td> </tr> </table>

xml xslt dynamic xpath row

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -