I want to create a table with xslt 1.0 from an XML source file containing a
varying number of key for each row :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<output>
<SearchResults>
<SearchResult>
<OTCreateDate>2009-10-27</OTCreateDate>
<OTCreatedByFullName>Jean-Philippe Martin</OTCreatedByFullName>
<Score>97</Score>
</SearchResult>
<SearchResult>
<Attr_4539360_16>Nord</Attr_4539360_16>
<Attr_4539360_26>Transférer</Attr_4539360_26>
<OTCreateDate >2007-08-30</OTCreateDate>
<OTCreatedByFullName >Caroline</OTCreatedByFullName>
<Score>94</Score>
</SearchResult>
</SearchResults>
</output>
So here my first key <SearchResult> have 3 sub-keys. But the second
<SearchResult> key have 5 sub-keys. I don't know what key will be present in
the set since it's a search result.
This would have to give an html which would look like this with 5 columns:
<html>
<body>
<table>
<thead>
<tr>
<th>OTCreateDate</th>
<th>OTCreatedByFullName</th>
<th>Score</th>
<th>Attr_4539360_16</th>
<th>Attr_4539360_26</th>
</tr>
</thead>
<tbody>
<tr>
<td>2009-10-27</td>
<td>Jean-Philippe Martin</td>
<td>97</td>
<td></td>
<td></td>
</tr>
<tr>
<td>2007-08-30</td>
<td>Caroline</td>
<td>94</td>
<td>Nord</td>
<td>Transférer</td>
</tr>
</tbody>
</table>
</body>
</html>
First, can it be done ?
For the head row I managed to get the unique key names with a M. Kay
algorithm I found but how to link a specific TD to its TH ?
<xsl:template match="/">
<table border="1">
<thead>
<tr>
<xsl:for-each select="//SearchResult/*">
<xsl:sort select="name(.)"/>
<xsl:if test="generate-id(.) = generate-id(key('names',
name(.))[1])">
<th>
<xsl:value-of select="local-name()"/>
</th>
</xsl:if>
</xsl:for-each>
</tr>
</thead>
</table>
</xsl:template>
Thank you for any help.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--