More poor man's Pipeline - adding Graphviz

I expanded the pipe function by allowing simple operators as steps. The first to be added was "dot" to transform an input dot format file through Graphviz to SVG.

To demonstrate this I wrote a small XQuery script which generates an XHTML with SVG generated by the pipes embedded in-line. Both views of the emp-dept database used in the SQL teaching are generated by a small pipeline with two steps each:

  • The first is an XQuery script to access the database and generate a dot format file (as XML) for input into ...
  • The second, denoted by "dot" in the pipe, passes the dot structure to Graphviz which returns SVG

Each pipe can be run on its own for testing, and the last parameter allows a shorter pipe to be run for testing.

A scaling transform is used to reduce the size of the image to fit the page

declare option exist:serialize "method=xhtml media-type=application/xhtml+xml omit-xml-declaration=no indent=yes 
        doctype-public=-//W3C//DTD XHTML 1.0 Strict//EN
<html xmlns=""
       <title>Views of a Company</title>
        <h1>Views of a Company</h1>
         <h2>Reporting hierarchy</h2>
            <svg:g transform="scale(0.4)">
        <h2>Departmental Structure</h2>
             <svg:g transform="scale(0.4)">

Show the Page

The script to generate the dot file is quite simple. For example, to generate the reporting hierarchy:

  digraph {{
 { for $emp in //Emp
   let $mgr := //Emp[EmpNo = $emp/MgrNo]
   where exists($mgr)
     <link>{$emp/Ename}  -> {$mgr/Ename} ; </link>

The dot step translates in an HTTP call:

 doc( concat(";dot=",encode-for-uri(normalize-space($doc))))

Performance is hardly sparkling because Graphviz is being run on a different server and interfaced with PHP. I simply must find time to integrate Graphviz with eXist as a module. 

Script development is hampered by caching so I need to add some cache-busting to the pipe. However I think this is a useful approach for simple sequences of transformations.