Difference between revisions of "How to create a XHTML word list with a Toolbox export process"
(→Notes) |
m (→Begin section) |
||
(10 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
Below there is a script for a "cct" (consistent changes table) to produce a word list in XHTML based on a Toolbox lexicon. | Below there is a script for a "cct" (consistent changes table) to produce a word list in XHTML based on a Toolbox lexicon. | ||
− | To use it copy and past the code into a text file (e.g. done with 'notepad') and then set up an export process. The description how to do it is in the comment. | + | To use it copy and past the code (see below) into a text file (e.g. done with 'notepad') and then set up an export process. The description how to do it is in the comment. |
==Notes== | ==Notes== | ||
Line 19: | Line 19: | ||
− | ==The | + | ==The code== |
<pre> | <pre> | ||
Line 29: | Line 29: | ||
C converts a part of Toolbox lexicon database | C converts a part of Toolbox lexicon database | ||
c | c | ||
− | c to | + | c to a XHTML table |
c | c | ||
c | c | ||
Line 49: | Line 49: | ||
c | c | ||
c To run the program the first time | c To run the program the first time | ||
− | c choose "File export" | + | c In Toolbox |
− | c | + | c choose menu "File" / "export" |
− | c | + | c choose "Add a new export process" |
− | c give a process name, e.g. | + | c click "Standard Format" button |
− | c and add this file as the changes table | + | c give a process name, e.g. WordListTableInXHTML |
+ | c and add this file as the changes table | ||
+ | c | ||
+ | c export the database file | ||
c | c | ||
− | |||
c | c | ||
c For subsequent execution do | c For subsequent execution do | ||
− | c choose "File export" | + | c choose "File export" |
− | c | + | c select the process 'WordListTableInXHTML' |
c | c | ||
c | c | ||
Line 122: | Line 124: | ||
− | begin > '<?xml version="1.0" encoding="UTF-8"?>' nl | + | begin > '<?xml version="1.0" encoding="UTF-8"?>' nl c XML header |
− | + | '<html xmlns="http://www.w3.org/1999/xhtml">' nl c root element -- HTML with name space declaration | |
− | + | '<header>' nl c start of HTML header | |
− | + | '<script language="JavaScript" type="text/javascript">' nl c dummy JavaScript area; replace with your code | |
− | + | ' function test(file, titleString)' nl | |
− | + | ' {' nl | |
− | + | ' //' nl | |
− | + | ' }' nl | |
− | + | '</script>' nl | |
− | + | ' ' | |
− | + | nl | |
− | + | '<link href="theStyleSheet.css" rel="stylesheet" type="text/css" />' nl c link to a CSS style sheet / fill in your css name | |
− | + | ' ' | |
− | + | nl | |
− | + | ' ' | |
− | + | nl | |
− | + | '<!-- additional styles --> ' nl | |
− | + | '<!-- delete the examples and replace them with what you want --> ' nl | |
− | + | '<style type="text/css">' nl | |
− | + | 'td.LexiconEntry {padding-bottom: 2px; color: black; font-size: 14;' nl | |
− | + | ' padding-left: 10px; padding-right: 10px; background-color="#C0FFCC";}' nl | |
− | + | nl | |
− | + | 'td.note {padding-bottom: 2px; color: black; font-size: 11;' nl | |
− | + | ' padding-left: 10px; padding-right: 10px; background-color="#A0FFA0";}' nl | |
− | + | nl | |
− | + | '</style>' nl | |
− | + | '</header>' nl c end of HTML header | |
− | + | ' ' | |
− | + | nl | |
− | + | ' ' | |
− | + | nl | |
− | + | '<body>' nl c start of HTML body | |
− | + | '<h2>' | |
− | + | 'Nkonya lexicon data' c title, replace with your title. | |
− | + | '</h2>' nl | |
− | + | ||
+ | '<table>' nl c start of lexical data / table form | ||
Line 282: | Line 285: | ||
</pre> | </pre> | ||
− | == Explantation of the consistent changes table == | + | == Explantation of the code (consistent changes table) == |
The code has four parts | The code has four parts | ||
Line 316: | Line 319: | ||
c | c | ||
c | c | ||
+ | c | ||
+ | c Instructions: | ||
+ | c put this file into the settings folder, the one within the Toolbox project folder. | ||
c | c | ||
c Instructions: | c Instructions: | ||
Line 322: | Line 328: | ||
c | c | ||
c To run the program the first time | c To run the program the first time | ||
− | c choose "File export" | + | c In Toolbox |
− | c | + | c choose menu "File" / "export" |
− | c | + | c choose "Add a new export process" |
− | c give a process name, e.g. | + | c click "Standard Format" button |
− | c and add this file as the changes table | + | c give a process name, e.g. WordListTableInXHTML |
+ | c and add this file as the changes table | ||
c | c | ||
− | c export the database file | + | c export the database file |
c | c | ||
− | |||
− | |||
− | |||
c | c | ||
+ | c For subsequent execution do | ||
+ | c choose "File export" | ||
+ | c select the process 'WordListTableInXHTML' | ||
c | c | ||
c | c | ||
Line 385: | Line 392: | ||
</pre> | </pre> | ||
− | |||
− | |||
− | |||
=== Begin section === | === Begin section === | ||
Line 399: | Line 403: | ||
− | + | begin > '<?xml version="1.0" encoding="UTF-8"?>' nl c XML header | |
− | + | '<html xmlns="http://www.w3.org/1999/xhtml">' nl c root element -- HTML with name space declaration | |
− | + | '<header>' nl c start of HTML header | |
− | + | '<script language="JavaScript" type="text/javascript">' nl c dummy JavaScript area; replace with your code | |
− | + | ' function test(file, titleString)' nl | |
− | + | ' {' nl | |
− | + | ' //' nl | |
− | + | ' }' nl | |
− | + | '</script>' nl | |
− | + | ' ' | |
− | + | nl | |
− | + | '<link href="theStyleSheet.css" rel="stylesheet" type="text/css" />' nl c link to a CSS style sheet / fill in your css name | |
− | + | ' ' | |
− | + | nl | |
− | + | ' ' | |
− | + | nl | |
− | + | '<!-- additional styles --> ' nl | |
− | + | '<!-- delete the examples and replace them with what you want --> ' nl | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | '<style type="text/css">' nl | ||
+ | 'td.LexiconEntry {padding-bottom: 2px; color: black; font-size: 14;' nl | ||
+ | ' padding-left: 10px; padding-right: 10px; background-color="#C0FFCC";}' nl | ||
+ | nl | ||
+ | 'td.note {padding-bottom: 2px; color: black; font-size: 11;' nl | ||
+ | ' padding-left: 10px; padding-right: 10px; background-color="#A0FFA0";}' nl | ||
+ | nl | ||
+ | '</style>' nl | ||
+ | '</header>' nl c end of HTML header | ||
+ | ' ' | ||
+ | nl | ||
+ | ' ' | ||
+ | nl | ||
+ | '<body>' nl c start of HTML body | ||
+ | '<h2>' | ||
+ | 'Nkonya lexicon data' c title, replace with your title. | ||
+ | '</h2>' nl | ||
+ | '<table>' nl c start of lexical data / table form | ||
+ | |||
c ------------------------------------------------------------- | c ------------------------------------------------------------- | ||
c define output procedures | c define output procedures | ||
Line 505: | Line 505: | ||
</pre> | </pre> | ||
− | |||
=== Main section === | === Main section === | ||
Line 575: | Line 574: | ||
endfile | endfile | ||
</pre> | </pre> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | == License == | ||
+ | |||
+ | The content of this wiki page is licensed under the [http://creativecommons.org/licenses/by-sa/3.0/deed.en_US Creative Commons Attribution-ShareAlike 3.0 Unported License]. The script code is under the [http://opensource.org/licenses/mit-license.php MIT license]. | ||
+ | |||
+ | This means you can use it in any project for anything as long as you attribute the source. You may as well copy this page to another web page and enhance it as long as you provide a link back to this page. |
Latest revision as of 12:42, 11 October 2012
The Toolbox program offers the feature to define various export processes.
The definition of an export process consists of
- a selection of fields
- a selection of records
- an optional transformation step written in the 'consistent changes' (cc) scripting language.
The cc scripting language is a domain specific language (DSL, more information).
Below there is a script for a "cct" (consistent changes table) to produce a word list in XHTML based on a Toolbox lexicon.
To use it copy and past the code (see below) into a text file (e.g. done with 'notepad') and then set up an export process. The description how to do it is in the comment.
Contents
Notes
- A line starting the letter 'c' indicates a comment.
- An XHTML file is primarily meant to be displayed in a web browser
- However it is possible to open it in a spreadsheet program as well and thus add additional data; the file may be later merged back to the Toolbox database it came from.
The code
C ======================================================================== C file name: genWordListInXHTMLtable.cct C based on: aswGenHTML.cct C C C converts a part of Toolbox lexicon database c c to a XHTML table c c c Fields: c \lx (lexeme) c \hm (homonym number) c \ps (part of speech) c \ge (gloss English) c c to XHTML-Code c c c c c c Instructions: c put this file into the settings folder, the one within the Toolbox project folder. c c c To run the program the first time c In Toolbox c choose menu "File" / "export" c choose "Add a new export process" c click "Standard Format" button c give a process name, e.g. WordListTableInXHTML c and add this file as the changes table c c export the database file c c c For subsequent execution do c choose "File export" c select the process 'WordListTableInXHTML' c c c c c Tamale, 4th October 2012 / Hannes Hirzel c c c Acknowledgement: c Karen Buseman reviewed the code and c provided suggestions to shorten it considerably. c c c c ------------------------------------------------------------------------------------------------------------------------------ c c http://opensource.org/licenses/mit-license.php c c c The MIT License (MIT) c c c c Copyright (c) 2012 Hannes Hirzel c c Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated c documentation files (the "Software"), to deal in the Software without restriction, including without limitation c the rights c to use, c copy, c modify, c merge, c publish, c distribute, c sublicense, c and/or sell copies of the Software, c c and to permit persons to whom the Software is furnished to do so, c c subject to the following conditions: c c The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. c c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c MERCHANTABILITY, c FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE c FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, c WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN c CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c c c ================================ =========================================================================================== c ---------------------------------------------------------- c write out complete HTML header including style information c ---------------------------------------------------------- begin > '<?xml version="1.0" encoding="UTF-8"?>' nl c XML header '<html xmlns="http://www.w3.org/1999/xhtml">' nl c root element -- HTML with name space declaration '<header>' nl c start of HTML header '<script language="JavaScript" type="text/javascript">' nl c dummy JavaScript area; replace with your code ' function test(file, titleString)' nl ' {' nl ' //' nl ' }' nl '</script>' nl ' ' nl '<link href="theStyleSheet.css" rel="stylesheet" type="text/css" />' nl c link to a CSS style sheet / fill in your css name ' ' nl ' ' nl '<!-- additional styles --> ' nl '<!-- delete the examples and replace them with what you want --> ' nl '<style type="text/css">' nl 'td.LexiconEntry {padding-bottom: 2px; color: black; font-size: 14;' nl ' padding-left: 10px; padding-right: 10px; background-color="#C0FFCC";}' nl nl 'td.note {padding-bottom: 2px; color: black; font-size: 11;' nl ' padding-left: 10px; padding-right: 10px; background-color="#A0FFA0";}' nl nl '</style>' nl '</header>' nl c end of HTML header ' ' nl ' ' nl '<body>' nl c start of HTML body '<h2>' 'Nkonya lexicon data' c title, replace with your title. '</h2>' nl '<table>' nl c start of lexical data / table form c ------------------------------------------------------------- c define output procedures c c c The output procedure will be called for each entry. c It produces one HTML table row. c Currently the row has two cells. c ------------------------------------------------------------- define(output_LexiconEntry) > if(lxFlag) begin "<tr>" c tr = table row; HTML table row mark '<td class="LexiconEntry">' out(lx) "</td>" nl '<td class="hm">' out(hm) '</td>' nl '<td class="ps">' out(ps) '</ td>' nl '<td class="ge">' out(ge) '</t d>' nl '<td class="sd">' nl out(sd) "</t d>" nl "</tr>" c end HTML table row nl nl c two new line commands do(clear_stores) c call procedure 'clear_Flags' defined below. end c if(lxFlag) define(clear_stores) > store(lx) endstore store(hm) endstore store(ps) endstore store(ge) endstore store(sd) endstore c --------------------------------------------------------------------------------------- nl > "" c eliminate new lines '\lx ' > endstore c stop storing and output previous entry if(lxFlag) c only output if lx has been encountered before, do(output_LexiconEntry) c i.e. if we are not at the very first record end if c then store new entry store(lx) c 'lx ' is name of data store set(lxFlag) c set lxFlag so for that all subsequent occurenences of lx c there will be output. '\hm ' > store(hm) c hm (homonym number) data store '\ps ' > store(ps) c ps (part of speech) data store '\ge ' > store(ge) c ge (gloss English) data store '\' > store(away) c eliminate all other fields by storing them c in another store called 'away' which we will not use. c ============================================================================================================ c c Treatment of last record and output of final HTML code c c ============================================================================================================ endfile > endstore do(output_LexiconEntry) c output last entry. "</table>" nl c end of table "</body>" nl "</html>" endfile
Explantation of the code (consistent changes table)
The code has four parts
- a comment section which describes the table
- a
begin
section which is executed once before the processing of the input file. - a main section (not labeled) which contains the processing rules.
- an
endfile
section which is executed after all the characters of the input file have been consumed.
Initial comment section
C ======================================================================== C file name: genWordListInXHTMLtable.cct C based on: aswGenHTML.cct C C C converts a part of Toolbox lexicon database c c to an HTML table c c c Fields: c \lx (lexeme) c \hm (homonym number) c \ps (part of speech) c \ge (gloss English) c c to XHTML-Code c c c c c c Instructions: c put this file into the settings folder, the one within the Toolbox project folder. c c Instructions: c put this file into the settings folder, the one within the Toolbox project folder. c c c To run the program the first time c In Toolbox c choose menu "File" / "export" c choose "Add a new export process" c click "Standard Format" button c give a process name, e.g. WordListTableInXHTML c and add this file as the changes table c c export the database file c c c For subsequent execution do c choose "File export" c select the process 'WordListTableInXHTML' c c c c Tamale, 4th October 2012 / Hannes Hirzel c c c Acknowledgement: c Karen Buseman reviewed the code and c provided suggestions to shorten it considerably. c c c c ------------------------------------------------------------------------------------------------------------------------------ c c http://opensource.org/licenses/mit-license.php c c c The MIT License (MIT) c c c c Copyright (c) 2012 Hannes Hirzel c c Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated c documentation files (the "Software"), to deal in the Software without restriction, including without limitation c the rights c to use, c copy, c modify, c merge, c publish, c distribute, c sublicense, c and/or sell copies of the Software, c c and to permit persons to whom the Software is furnished to do so, c c subject to the following conditions: c c The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. c c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c MERCHANTABILITY, c FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE c FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, c WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN c CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c c c ================================ ===========================================================================================
Begin section
c ---------------------------------------------------------- c write out complete HTML header including style information c ---------------------------------------------------------- begin > '<?xml version="1.0" encoding="UTF-8"?>' nl c XML header '<html xmlns="http://www.w3.org/1999/xhtml">' nl c root element -- HTML with name space declaration '<header>' nl c start of HTML header '<script language="JavaScript" type="text/javascript">' nl c dummy JavaScript area; replace with your code ' function test(file, titleString)' nl ' {' nl ' //' nl ' }' nl '</script>' nl ' ' nl '<link href="theStyleSheet.css" rel="stylesheet" type="text/css" />' nl c link to a CSS style sheet / fill in your css name ' ' nl ' ' nl '<!-- additional styles --> ' nl '<!-- delete the examples and replace them with what you want --> ' nl '<style type="text/css">' nl 'td.LexiconEntry {padding-bottom: 2px; color: black; font-size: 14;' nl ' padding-left: 10px; padding-right: 10px; background-color="#C0FFCC";}' nl nl 'td.note {padding-bottom: 2px; color: black; font-size: 11;' nl ' padding-left: 10px; padding-right: 10px; background-color="#A0FFA0";}' nl nl '</style>' nl '</header>' nl c end of HTML header ' ' nl ' ' nl '<body>' nl c start of HTML body '<h2>' 'Nkonya lexicon data' c title, replace with your title. '</h2>' nl '<table>' nl c start of lexical data / table form c ------------------------------------------------------------- c define output procedures c c c The output procedure will be called for each entry. c It produces one HTML table row. c Currently the row has two cells. c ------------------------------------------------------------- define(output_LexiconEntry) > if(lxFlag) begin "<tr>" c tr = table row; HTML table row mark '<td class="LexiconEntry">' out(lx) "</td>" nl '<td class="hm">' out(hm) '</td>' nl '<td class="ps">' out(ps) '</ td>' nl '<td class="ge">' out(ge) '</t d>' nl '<td class="sd">' nl out(sd) "</t d>" nl "</tr>" c end HTML table row nl nl c two new line commands do(clear_stores) c call procedure 'clear_Flags' defined below. end c if(lxFlag) define(clear_stores) > store(lx) endstore store(hm) endstore store(ps) endstore store(ge) endstore store(sd) endstore
Main section
c --------------------------------------------------------------------------------------- nl > "" c eliminate new lines '\lx ' > endstore c stop storing and output previous entry if(lxFlag) c only output if lx has been encountered before, do(output_LexiconEntry) c i.e. if we are not at the very first record end if c then store new entry store(lx) c 'lx ' is name of data store set(lxFlag) c set lxFlag so for that all subsequent occurenences of lx c there will be output. '\hm ' > store(hm) c hm (homonym number) data store '\ps ' > store(ps) c ps (part of speech) data store '\ge ' > store(ge) c ge (gloss English) data store '\' > store(away) c eliminate all other fields by storing them c in another store called 'away' which we will not use.
Endfile section
c ============================================================================================================ c c Treatment of last record and output of final HTML code c c ============================================================================================================ endfile > endstore do(output_LexiconEntry) c output last entry. "</table>" nl c end of table "</body>" nl "</html>" endfile
License
The content of this wiki page is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. The script code is under the MIT license.
This means you can use it in any project for anything as long as you attribute the source. You may as well copy this page to another web page and enhance it as long as you provide a link back to this page.