Mon Dec 09, 2019 12:33 pm
Login Register Lost Password? Contact Us


Converting DATASET to HTML <Table>

Questions around writing code and queries

Fri Jun 28, 2019 9:51 am Change Time Zone

Hi,

I can't believe this has not been done, but I can't find anything on the forum.
I have a bog standard DATASET (containing all STRING fields) that I just want to convert to a HTML table construct, e.g.
Code: Select all
<table><tr><td>r1 c1</td><td>r1 c2</td></tr><tr><td>r2 c1</td><td>r2 c2</td></tr></table>


Anyone already done this, so I'm not re-inventing the Wheel.

Thanks

Allan
Allan
 
Posts: 386
Joined: Sat Oct 01, 2011 7:26 pm

Fri Jun 28, 2019 12:51 pm Change Time Zone

Allan,

Here's an example that I wrote awhile ago to generate XML, and as you can see, have just modified to create your table:
Code: Select all
SetLtr := ['A','B','C','D','E','F','G','H','I','J','K','L'];
ds := DATASET(12,TRANSFORM({UNSIGNED1 UID,STRING1 Ltr},
                           SELF.UID := COUNTER,
                           SELF.Ltr := SetLtr[COUNTER]));
// ds;

Rec := {STRING xmltxt};
// StartXML := '<XML>';
// EndXML   := '</XML>';
// BldRow(UNSIGNED1 uid, STRING1 Ltr) :=
//   '<row><uid>' + (STRING)uid + '</uid><ltr>' + ltr + '</ltr></row>';
StartXML := '<table>';
EndXML   := '</table>';
BldRow(UNSIGNED1 uid, STRING1 Ltr) :=
   '<tr><td>' + (STRING)uid + '</td><td>' + ltr + '</td></tr>';
p := PROJECT(ds,
             TRANSFORM(Rec,
                       SELF.xmltxt := BldRow(LEFT.UID,LEFT.Ltr)));
r := ROLLUP(p,TRUE,
            TRANSFORM(Rec,
                      SELF.xmltxt := LEFT.xmltxt + RIGHT.xmltxt
                         ));
StartXML + r[1].xmltxt + EndXML;

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1488
Joined: Wed Oct 26, 2011 7:40 pm

Fri Jun 28, 2019 1:37 pm Change Time Zone

Thanks, Richard

Could this go into 'tips-and-tricks'?

Yours

Allan
Allan
 
Posts: 386
Joined: Sat Oct 01, 2011 7:26 pm

Fri Jun 28, 2019 6:00 pm Change Time Zone

Sure
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1488
Joined: Wed Oct 26, 2011 7:40 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest