CSV to HTML translation: Difference between revisions

Content deleted Content added
Aartaka (talk | contribs)
Add ed example
Kennypete (talk | contribs)
Added OmniMark solution
Line 4,269: Line 4,269:
</table>
</table>
</html></syntaxhighlight>
</html></syntaxhighlight>

=={{header|OmniMark}}==
Only the "extra credit" version is provided here. It is also XHTML 1.0, complete, and validates (as noted in the comment to the 'process-end' rule). The validation could be done by OmniMark too, but that's going well beyond the scope of the task. Only the three XML character references, which appear in the input, are included - &amp;gt;, &amp;lt;, and &amp;apos; (so, not &amp;amp; and &amp;quot;). Output XHTML, plus a thumbnail screenshot of the output and the Firefox Inspector output, is included.

<syntaxhighlight lang=omnimark>
global switch thead initial {true}
global switch tbody-first initial {true}

define function process-tr (value stream line) as
do when thead
output '<thead>%n<tr><th>'
else when tbody-first
output '</thead>%n'
output '<tbody>%n<tr><td>'
deactivate tbody-first
else
output '<tr><td>'
done
repeat scan line
match ',' any-text => char
output '</th><th>' when thead
output '</td><td>' unless thead
using group ents submit char
match any-text => char
using group ents submit char
again
output '</td>' unless thead
output '</th>' when thead
output '</tr>'
deactivate thead


process-start
output '<?xml version="1.0" encoding="UTF-8"?>%n' ||
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">%n' ||
'<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">%n' ||
'<head>%n' ||
'<title>Monty Python’s Life of Brian (1979). Scene 20 (extract).</title>%n' ||
'<meta name="description" content="Rosetta Code. Task: CSV to HTML translation (extra credit)" />%n' ||
'<meta name="keywords" content="OmniMark" />%n' ||
'<meta name="author" content="Kennypete" />%n' ||
'<style type="text/css">%nth { background-color: gold }%n</style>%n' ||
'</head>%n' ||
'<body>%n' ||
'<table border=%"1%">%n'

process-end
output '</tbody>%n' ||
'</table>%n' ||
'</body>%n' ||
'</html>%n'
; Output validates to XHTML 1.0 - https://validator.w3.org/check

process
local stream s
set s to "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"
using group line submit s

group ents

find '<'
output '&lt;'

find '>'
output '&gt;'

find "'"
output '&apos;'

group line

find line-start any-text+ => line
process-tr(line)
</syntaxhighlight>

{{out}}

[[File:20240714-CSV-to-HTML-translation.png|thumb|alt=OmniMark CSV-to-HTML-translation Firefox output and Inspector|Firefox output and Inspector]]

<syntaxhighlight lang=html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Monty Python’s Life of Brian (1979). Scene 20 (extract).</title>
<meta name="description" content="Rosetta Code. Task: CSV to HTML translation (extra credit)" />
<meta name="keywords" content="OmniMark" />
<meta name="author" content="Kennypete" />
<style type="text/css">
th { background-color: gold }
</style>
</head>
<body>
<table border="1">
<thead>
<tr><th>Character</th><th>Speech</th></tr>
</thead>
<tbody>
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
<tr><td>Brians mother</td><td>&lt;angry&gt;Now you listen here! He&apos;s not the messiah; he&apos;s a very naughty boy! Now go away!&lt;/angry&gt;</td></tr>
<tr><td>The multitude</td><td>Who are you?</td></tr>
<tr><td>Brians mother</td><td>I&apos;m his mother; that&apos;s who!</td></tr>
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
</tbody>
</table>
</body>
</html>
</syntaxhighlight>


=={{header|OpenEdge/Progress}}==
=={{header|OpenEdge/Progress}}==