From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Bogner Subject: Calling org babel to each row in a table Date: Sun, 30 Jun 2013 11:25:22 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bacc17c68188704e060b83f Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtJVF-0003nH-TD for emacs-orgmode@gnu.org; Sun, 30 Jun 2013 11:25:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UtJVC-0004Wx-Rn for emacs-orgmode@gnu.org; Sun, 30 Jun 2013 11:25:25 -0400 Received: from mail-ve0-x230.google.com ([2607:f8b0:400c:c01::230]:46582) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtJVC-0004Wf-O3 for emacs-orgmode@gnu.org; Sun, 30 Jun 2013 11:25:22 -0400 Received: by mail-ve0-f176.google.com with SMTP id c13so3056967vea.21 for ; Sun, 30 Jun 2013 08:25:22 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --047d7bacc17c68188704e060b83f Content-Type: text/plain; charset=ISO-8859-1 I often need to transform a table or list of values into a block of text. For example, if I have a list of 4 files that I want to generate a SQL script for. After hunting around, this is the best I came up with: #+name: table | File | | a | | b | | c | | d | #+name: template #+begin_src org :results verbatim :var name="abc" DROP TABLE $name CREATE TABLE $name (name varchar(100)) BULK INSERT $name FROM '\\1.1.1.1\$name.txt' ... #+end_src #+name: apply-template #+begin_src emacs-lisp :results silent :var table=() (let (result-table) (dolist (line (cdr table)) (setq result-table (cons (concat "#+call: template(\"" (car line) "\") :results raw drawer") result-table))) (mapconcat 'identity (nreverse result-table) "\n")) #+end_src #+call: apply-template(table) :results org :exports both #+RESULTS: apply-template(table):results org :exports both #+BEGIN_SRC org #+END_SRC Is there a more straightforward method to apply this type of transformation? Ideally I would skip the emacs-lisp block and use some syntax to apply a org-babel block for each row in a table. It sounded similar to this: http://thread.gmane.org/gmane.emacs.orgmode/69326/focus=69340*, *but that didn't have a full example for me to build off of Is there a more straightforward to accomplish this transformation? Thanks, Joe --047d7bacc17c68188704e060b83f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I often need to transform a table or list of values into a= block of text. For example, if I have a list of 4 files that I want to gen= erate a SQL script for.

After hunting around, this is th= e best I came up with:

#+name: table
| File |
| = a =A0 =A0|
| b =A0 =A0|
| c =A0 =A0|
| d =A0 = =A0|

#+name: template=A0
#+begin_src org= :results verbatim :var name=3D"abc"
DROP TABLE $name

CREATE TABLE $name (name var= char(100))

BULK INSERT $name FROM '\\1.1.1.1\$= name.txt' ...
#+end_src

#+name: appl= y-template=A0
#+begin_src emacs-lisp :results silent :var table=3D()
(let = (result-table)
=A0 =A0 (dolist (line (cdr table))
=A0 = =A0 =A0 =A0 (setq result-table (cons (concat "#+call: template(\"= " (car line) "\") :results raw drawer") result-table)))=
=A0 =A0 (mapconcat 'identity (nreverse result-table) "\n"= ;))
#+end_src

#+call: apply-template(tab= le) :results org :exports both

#+RESULTS: apply-te= mplate(table):results org :exports both
#+BEGIN_SRC org
#+END_SRC


Is there a more straightforward method to = apply this type of transformation? Ideally I would skip the emacs-lisp bloc= k and use some syntax to apply a org-babel block for each row in a table.


It sounded simila= r to this:=A0http://thread.gmane.org/gmane.emacs.orgmode= /69326/focus=3D69340, but that didn't have a full example fo= r me to build off of

Is there a more straightforward to accomplish this tran= sformation?

Thanks,
Joe
--047d7bacc17c68188704e060b83f--