CSV to HTML translation: Difference between revisions

Add Seed7 example
(→‎{{header|TXR}}: This is released.)
(Add Seed7 example)
Line 2,260:
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
</table></lang>
 
=={{header|Seed7}}==
The library [http://seed7.sourceforge.net/libraries/html_ent.htm html_ent.s7i] defines the
function [http://seed7.sourceforge.net/libraries/html_ent.htm#encodeHtmlContent%28in_string%29 encodeHtmlContent],
which replaces characters with HTML entities. E.g.: '<' is replaced by ''&amp;lt;''.
<lang seed7>$ include "seed7_05.s7i";
include "html_ent.s7i";
 
const string: csvData is "\
\Character,Speech\n\
\The multitude,The messiah! Show us the messiah!\n\
\Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>\n\
\The multitude,Who are you?\n\
\Brians mother,I'm his mother; that's who!\n\
\The multitude,Behold his mother! Behold his mother!\n";
 
const proc: main is func
local
var string: line is "";
var string: column is "";
const array [boolean] string: columnStartTag is [boolean] ("<td>", "<th>");
const array [boolean] string: columnEndTag is [boolean] ("</td>", "</th>");
var boolean: firstLine is TRUE;
begin
writeln("<table>");
for line range split(csvData, '\n') do
write("<tr>");
for column range split(line, ',') do
write(columnStartTag[firstLine] <& encodeHtmlContent(column) <& columnEndTag[firstLine]);
end for;
writeln("</tr>");
firstLine := FALSE;
end for;
writeln("</table>");
end func;</lang>
 
Output:
<pre>
<table>
<tr><th>Character</th><th>Speech</th></tr>
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
<tr><td>Brians mother</td><td>&lt;angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!&lt;/angry></td></tr>
<tr><td>The multitude</td><td>Who are you?</td></tr>
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
<tr><td></td></tr>
</table>
</pre>
 
Output viewed with a browser:
<table>
<tr><th>Character</th><th>Speech</th></tr>
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
<tr><td>Brians mother</td><td>&lt;angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!&lt;/angry></td></tr>
<tr><td>The multitude</td><td>Who are you?</td></tr>
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
<tr><td></td></tr>
</table>
 
=={{header|Tcl}}==