Trying to transform XML to HTML tables. I can find plenty of examples on creating an XSLT style sheet for XML where the format is like this:
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
</cd>
</catalog>
But what if the format is like this, as it is in my dataset?
<DataObjects>
<ObjectSelect>
<mdNm>my-catalog</mdNm>
<meNm>Catalog Selection A1</meNm>
</ObjectSelect>
<DataInstances>
<DataInstance>
<instanceId>Cd</instanceId>
<field name='title'>Empire Burlesque</field>
<field name='artist'>Bob Dylan</field>
<field name='country'>USA</field>
<field name='company'>Columbia</field>
</DataInstance>
<DataInstance>
<instanceId>Movie</instanceId>
<field name='title'>Casablanca</field>
<field name='director'>Michael Curtiz</field>
<field name='genre'>Drama</field>
</DataInstance>
</DataInstances>
</DataObjects>
Each InstanceId has a single entry, with unique field names, and I'm trying to get create a table output for each unique InstanceId, so a "Cd" table, a "Movie" table, and so on. Each field would be a new row, the first column would be what is in name=, and the value would be in the second column of the row. I think once I figure out how to grab the value from name="" and put it as a row name, I'll be able to figure out the rest. All the tutorials talk about using value-of, but that only works if the format is like the first example given.
An example XSLT that I'm using as a starting point. It does not like the field name= format.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Catalog Selection A1</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name</th>
<th>Value</th>
</tr>
<xsl:for-each select="DataObjects/DataInstances/DataInstance/instanceId/Cd">
<tr>
<td>Title</td>
<td><xsl:value-of select="title" /></td>
</tr>
<tr>
<td>Artist</td>
<td><xsl:value-of select="artist" /></td>
</tr>
<tr>
<td>Country</td>
<td><xsl:value-of select="country" /></td>
</tr>
<tr>
<td>Company</td>
<td><xsl:value-of select="company" /></td>
</tr>
</xsl:for-each>
<xsl:for-each select="DataObjects/DataInstances/DataInstance/instanceId/Movie">
<tr>
<td>Title</td>
<td><xsl:value-of select="title" /></td>
</tr>
<tr>
<td>Director</td>
<td><xsl:value-of select="director" /></td>
</tr>
<tr>
<td>Genre</td>
<td><xsl:value-of select="genre" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The output I'm trying to generate is a basic html table like this,
<html>
<body>
<h2>Catalog Selection A1</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name</th>
<th>Value</th>
</tr>
<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>
</table>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name</th>
<th>Value</th>
</tr>
<tr>
<td>Title</td>
<td>Casablanca</td>
</tr>
<tr>
<td>Director</td>
<td>Michael Curtiz</td>
</tr>
<tr>
<td>Genre</td>
<td>Drama</td>
</tr>
</table>
</body>
</html>
tag in the output.