XQuery/Dataflow diagrams

From Wikibooks, open books for an open world
Jump to navigation Jump to search

This description of the data flow in the Timetable application (another page scraping application) is loosely based on XPL

<?xml version="1.0" encoding="UTF-8"?>
<Pipeline id="timetable">
        <process id="i1">
            <title>Input id</title>
        <process id="i2">
            <title>input week number</title>
        <process id="i3">
            <title>input role</title>
        <process id="s1">
            <title>create url</title>
         <process id="s2">
            <title>get html</title>
        <process id="x1">
            <title>Syllabus Plus</title>
        <process id="s3">
            <title>convert to xhtml</title>
        <process id="s4">
            <title>extract xml</title>
        <process id="s5">
            <title>transform to vcal</title>
        <process id="s6">
            <title>transform to htm</title>

With a map from types to shapes:

    <type name="input" shape="invtriangle"/>
    <type name="process" shape="box"/>
    <type name="external" shape="house"/>

Conversion to dot format for onward conversion to a GIF image

declare option exist:serialize "method=text";
declare variable $nl := "
declare variable $url := request:get-parameter("url","/db/Wiki/DataFlow/timetablexpl.xml");
declare variable $processTypes := /ProcessTypes;
let $pipe  := doc($url)

return   (
  "digraph {" ,
   for $process in $pipe//process 
   let $type := 
        if (exists($process/type))
        then $process/type
        else if (empty($process/input))
        then "input"
        else "process"
    let $shape :=  string($processTypes/type[@name=$type]/@shape)
      ( concat ($process/@id, ' [shape=',$shape,',label="',$process/title, '"];',$nl),
         for $input in $process/input
           concat($input, '->', $process/@id,";",$nl)
   "} ",$nl

Dot file Diagram