CSV to HTML translation: Difference between revisions

Content added Content deleted
(Restore MATLAB example, deleted by Bbsingapore.)
(→‎{{header|TXR}}: Bonus points version.)
Line 2,821: Line 2,821:


=={{header|TXR}}==
=={{header|TXR}}==

====Simple====


<lang txr>@(collect)
<lang txr>@(collect)
Line 2,835: Line 2,837:
</table>
</table>
@(end)</lang>
@(end)</lang>

Note some similarities in the output generation to the AWS template system in the [[#Ada|Ada]] solution.
In AWS, <code>@@TABLE@@</code> does something similar to TXR's <code>@(repeat)</code>: repeating the section of a template as many times as the vector variables have items.


Output:
Output:
Line 2,869: Line 2,868:
</tr>
</tr>
</table></lang>
</table></lang>

====With Styling====

<lang txr>@(collect)
@char,@speech
@(end)
@(output :filter :to_html)
<style type="text/css">
tr.odd td {
background-color: #CC9999; color: black;
}
tr.even td {
background-color: #9999CC; color: black;
}
th {
background-color: #99CC99; color: black;
}
</style>
<table>
@ (repeat :counter row)
<tr class="@(if (evenp row) "even" "odd")">
<td>@char</td>
<td>@speech</td>
</tr>
@ (first)
<tr>
<th>@char</th>
<th>@speech</th>
</tr>
@ (end)
</table>
@(end)</lang>

Output:

<pre>$ txr csv2.txr csv.txt</pre>
<lang html5><style type="text/css">
tr.odd td {
background-color: #CC9999; color: black;
}
tr.even td {
background-color: #9999CC; color: black;
}
th {
background-color: #99CC99; color: black;
}
</style>
<table>
<tr>
<th>Character</th>
<th>Speech</th>
</tr>
<tr class="odd">
<td>The multitude</td>
<td>The messiah! Show us the messiah!</td>
</tr>
<tr class="even">
<td>Brians mother</td>
<td>&lt;angry&gt;Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!&lt;/angry&gt;</td>
</tr>
<tr class="odd">
<td>The multitude</td>
<td>Who are you?</td>
</tr>
<tr class="even">
<td>Brians mother</td>
<td>I'm his mother; that's who!</td>
</tr>
<tr class="odd">
<td>The multitude</td>
<td>Behold his mother! Behold his mother!</td>
</tr>
</table></lang>

Rendered:
[[File:txr-csv.jpg]]


=={{header|Vedit macro language}}==
=={{header|Vedit macro language}}==