/* NetRexx */ options replace format comments java crossref symbols nobinary -- create some test data. Put the data in a Rexx indexed string maxI = 1000 rng = Random() xyz = '' xyz[0] = 1; xyz[1] = '. X Y Z' -- use a dot to indicate an empty cell loop r_ = 1 for 5 ra = r_ rng.nextInt(maxI) rng.nextInt(maxI) rng.nextInt(maxI) xyz[0] = r_ + 1; xyz[r_ + 1] = ra end r_ -- build an HTML string html = htmlHeader() html = html || htmlTable(xyz) html = html || htmlFooter() -- display HTML at standard output device say html return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- HTML boilerplate header -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method htmlHeader() public static returns Rexx html = '\n' - || '\n' - || '\n' - || '\n' - || '\n' - || 'RCreateHTMLTable\n' - || '\n' - || '\n' - || '\n' - || '

Rosetta Code – NetRexx Sample Output

\n' - || '

Create an HTML table

\n' - || '' return html -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- HTML footer -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method htmlFooter() public static returns Rexx html = '\n' - || '\n' - || '' return html -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Create the table -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method htmlTable(rows, caption = '') public static returns Rexx html = '\n' if caption.length() > 0 then do html = html - || '\n' - || '\n' - || '' end html = html - || htmlCsvTableRow(rows[1], 'th')'\n' - || '\n' - || '\n' - || '' loop r_ = 2 to rows[0] html = html - || htmlCsvTableRow(rows[r_]) end r_ html = html - || '\n' - || '
'caption'
\n' - || '' return html -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Add a row to the table -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method htmlCsvTableRow(row, tag = 'td', sep = ' ', emptyCell = '.') public static returns Rexx if tag = null then tag = 'td' row = row.strip('t') -- replace HTML special characters with symbol entities row = row.changestr('&', '&') -- need to do this one first to avoid double translation row = row.changestr('"', '"') row = row.changestr("'", ''') row = row.changestr('<', '<') row = row.changestr('>', '>') elmts = '' elmts[0] = 0 e_ = 0 loop while row.length() > 0 parse row elmt (sep) row if elmt == emptyCell then elmt = ' ' -- replace empy cells with non-breaking spaces e_ = e_ + 1; elmts[0] = e_; elmts[e_] = elmt end html = '\n' - || '' loop e_ = 1 to elmts[0] html = html - || '<'tag'>'elmts[e_]'\n' - || '' end e_ html = html - || '\n' - || '' return html