Search

Poor man's Pipeline

XProc is a wonderful thing, and very powerful. However for simple situations it may be overly complex.  In the case of transforming an Excel spreadsheet to a visualisation, perhaps a simpler, more specific pipeline implementation might do.

The step-by step transformation in the last example leads to a recursive function and its front-door:



declare function local:execute-step($doc,$steps as xs:string* ) {
 if (empty($steps)) then $doc
 else 
     let $step := $steps[1]
     let $newdoc := 
         if (exists($doc))
         then
              let $xslt := doc($step)
              return
                 if (ends-with($step,".xsl"))
                 then transform:transform($doc,$xslt,())
                 else $doc
         else 
            if (ends-with($step,".xls"))
            then doc(concat("http://elev.at/lift?xls=",$step))
            else doc($step)
    return 
        local:execute-step($newdoc, subsequence($steps,2))
};

declare function local:execute-pipe($pipe as xs:string ,$last as xs:integer)  {
  let $steps := subsequence(tokenize($pipe,";"),1,$last)
  return   local:execute-step((),$steps)
};


$last limits the steps to run for testing. Operations on steps is determined by the file suffix.

A simple interface:

let $last := xs:integer(request:get-parameter("last",999))
let $pipe := request:get-parameter("pipe",())
return local:execute-pipe($pipe,$last)


And a call:

http://www.cems.uwe.ac.uk/xmlwiki/graph2svg/pipe.xq?pipe=http://www.communities.gov.uk/documents/statistics/xls/1403043.xls;/db/Wiki/graph2svg/xsl2fire.xsl;/db/Wiki/graph2svg/fires.xsl;/db/Wiki/graph2svg/xmsgr2svg.xsl 

; is not the best choice of a separator. the pipe symbol would be better.