Examples of Transmorpher flows
These examples may be found in the sample directory of the repository,
illustrated by this link if you have cloned the repository.
Dangling links may also be found there.
Music
Music has been designed to be the new entry point example for
illustrating Transmorpher.
Processing
As for the other examples, the bast way to process it is to do the
following:
$ cd samples
$ java -jar ../lib/transmo.jar file:music/process.xml
$
That's it. Read below to see what happens behind the scene.
Data
The sample is quite simple :
The objective of the set of transformation is to present these data
in different form. In this exemple, it provided three formats:
- A Html presentation of discography data, with time info stripped
and links to possible concert scedule (Music-collection.html);
- A Html presentation of concert schedule linked to discographic
information (artist.html) ;
- A vCalendar presentation of the concert schedule for inclusion in
a calendar application (artist.vcs);
These files should have been generated in the output directory by the execution above and
they are displayed below in the result part.
Transmorpher uses several external XSLT stylesheets:
More elaborate resources for dealing with vCalendar and icalendar are
available in the contribution directory of Transmorpher.
Transmorpher transformation
The listing of the transformation is given verbatim below. Its
structure is provided by the following transformation flow.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE transmorpher SYSTEM "../../dtd/transmorpher.dtd">
<transmorpher name="Music" version="1.0" reloc="music/results" xmlns="http://transmorpher.fluxmedia.fr/1.0">
<!-- select an artist -->
<query name="artist" type="tmq" root="music-collection">
<param name="artist" select="TEST"/>
<select match="music-collection/owner"/>
<select match="music-collection/artist" test="name=translate($artist,'_',' ')"/>
</query>
<!-- removes all tag <time></time> -->
<ruleset name="stripTime">
<remtag match="time" context="track"/>
</ruleset>
<main name="Collection">
<param name="artist">No_Doubt</param>
<param name="filename">Music-collection</param>
<generate id="generateXML" type="readfile" out="o">
<with-param name="file">../samples/music/input/${filename}.xml</with-param>
</generate>
<dispatch id="disp" type="broadcast" in="o" out="o1 o2"/>
<apply-ruleset ref="stripTime" id="Strip" in="o1" out="o11"/>
<apply-external id="xml2html" in="o11" out="o12" type="xslt">
<with-param name="file">../samples/music/xslt/${filename}.xsl</with-param>
</apply-external>
<serialize id="FormHTML" type="writefile" in="o12">
<with-param name="file">../samples/music/output/${filename}.html</with-param>
<with-param name="indent">yes</with-param>
</serialize>
<apply-query type="tmq" ref="artist" id="query" in="o2" out="o22">
<with-param name="artist">${artist}</with-param>
</apply-query>
<apply-external id="xml2html" in="o22" out="o23" type="xslt">
<with-param name="file">../samples/music/xslt/${filename}.xsl</with-param>
<with-param name="artist">${artist}</with-param>
</apply-external>
<serialize id="FormArtistHTML" type="writefile" in="OUT">
<with-param name="file">../samples/music/output/${artist}.html</with-param>
<with-param name="indent">yes</with-param>
<with-param name="method">xhtml</with-param>
</serialize>
<generate id="generateXML" type="readfile" out="a1">
<with-param name="file">../samples/music/input/${artist}-cal.xml</with-param>
<!-- <with-param name="type">vcal</with-param> -->
</generate>
<dispatch id="dispatch" type="broadcast" in="a1" out="a11 a12"/>
<apply-external id="xml2cal" in="a11" out="a21" type="xslt">
<with-param name="file">../samples/music/xslt/form-xvcs.xsl</with-param>
<with-param name="method">text</with-param>
</apply-external>
<serialize id="FormCAL" type="writefile" in="a21">
<with-param name="file">../samples/music/output/${artist}.vcs</with-param>
<with-param name="indent">yes</with-param>
<with-param name="method">text</with-param>
</serialize>
<apply-external id="xml2cal" in="a12" out="a22" type="xslt">
<with-param name="file">../samples/music/xslt/artist-cal.xsl</with-param>
<with-param name="artist">${artist}</with-param>
</apply-external>
<merge id="merger" type="concat" in="o23 a22" out="OUT"/>
</main>
</transmorpher>
This stylesheet illustrates:
- The definition of a ruleset;
- The definition of a query;
- The use of variables and parameter passing;
- The use of external XSLT stylesheets;
- The dispatching and merging of streams;
- The serialization of HTML and other formats.
Results
HTML output with cross-links.
vCalendar output imported in iCal.
The bibliography example
This is a more sophisticated example, that used to be the entry
point example for Transmorpher. However, it has evolved in a rather
complicated example, involving many different external add-ons
(e.g., it now generated RDF, RTF, etc).
Moreover, this example is also used for generating a servlet. See
http://www.inrialpes.fr/exmo/papers.
The old presentation of this example is thus given here for
illustration purposes; it provides a good view of what is possible
with Transmorpher.
Data
The sample is quite simple :
we have a DTD which discribe a list of bibligoraphy
references :
A reference is an element which contains differents informations like
: authors, title of article, abstract; ....
The objective of the set of transformation is to present this set of
references in different form. In this exemple, we want to have four presentation.
- A Html presentation ordered by year of publication (see);
- A Html presentation ordered by author ;
- A Html presentation ordered by conference type (see);
- A list of bibtex entry (see).
To do this, we have defined a set of XSL files, and used the transmorpher
to combine the differents XSL file.
This agregation is descibred in the 3 samples :
Sample 1 : this is a simple transformation
(see Sample 1 )
Sample 2 : this is a simple transformation
with a query (see Sample 2 )
Sample 3 : this is a more complex transformation
(see Sample 3 )
Also, in the performance analysis (see performance)
you can find a discussion on improvment issue.
<reference index="bougé2000a" type="inproceedings" language="fr">
<authors>
<p first="Patrick" last="Bougé"/>
<p first="Jérôme" last="Euzenat"/>
<p first="Jean-Paul" last="Barthès"/>
</authors>
<title>Localisation des connaissances dans les systèmes de production</title>
<conference type="journées" name="Gestion de connaissances" sponsor="Prosper">
<location city="Toulouse" country="FR"/>
</conference>
<year>2000</year>
<date>7-8 juin</date>
<pages>31-50</pages>
<links>
<url href="http://www.univ-valenciennes.fr//Prosper-loc-formatted.zip" status="public"/>
<url href="ftp://ftp.inrialpes.fr//bouge2000a.ps.gz" status="public"/>
</links>
<abstract>La gestion des connaissances s'instancie de manière
extrèmement variée au sein des entreprises et elle mobilise
des disciplines tout aussi ariées. Les connaissances considérées
par les différentes approches peuvent être très différentes.
On peut se demander si cet état de fait est dû aux approches
mises en oeuvre ou exigé par la variété des applications
englobées par la gestion de connaissance. On considère un
ensemble de projets pouvant être considérés comme relevant
de la gestion de connaissance restreinte au cadre des systèmes de
productions. .</abstract>
<areas>
<li>Knowledge management/Gestion de connaissance</li>
</areas>
<contracts><li>ardeco</li></contracts>
</reference>
|
Figure 1.0 : A Reference
For example :
this description defines a complex transformation
shown in figure 1.0
<?xml version="1.0" encoding="UTF-8"?>
<transmorpher xmlns:tm="http://fluxlog1.inrialpes.fr/0.1">
<!-- WARNING ... this sample doesn't work alone, is
part of the complex sample, it was split to simplify the presentation of
the example -->
<!-- Definition of the rule set.
This rule set remove two kind of elements :
- the first rule remove elements abstract or keywords or areas or .... in
reference element
- the second rule remove reference with an attribute status which as a value
: private
The strip abstract can be done in XML, see here
for a discussion on that points.
-->
<ruleset name="stripAbstract">
<remtag match="abstract|keywords|areas|softwares|contracts" content="reference"/>
<remtag match="*[status='private']" content="reference"/>
</ruleset>
<process name="myFirstprocess" in="R112" out="X3 Y3 Z3">
<!--
This element split the XML flow in Two XML flow, the two flow contains
the same informations */
<dispatch name="Dispatcher1" in="R112" out="D1 D3"/>
<!-- this element remove the hidden element in the biblography -->
<apply-external type="xslt" name="XLST11" file="strip-hidden.xsl" in="D1" out="X1"/>
<!--
This element split the XML flow in Two XML flow, the two flow contains
the same informations */
<dispatch name="Dispatcher2" in="X1" out="X11 X12"/>
<!-- this element sort the biblography by title and year -->
<apply-external type="xslt" name="XLST21" file="sort-ty.xsl" in="X11" out="X2"/>
<!-- this element compute the presentation -->
<apply-external type="xslt" name="XLST31" file="form-harea.xsl" in="X2" out="X3"/>
<!-- this element sort the biblography by content, year and author -->
<apply-external type="xslt" name="XLST22" file="sort-cya.xsl" in="X12" out="Y2"/>
<!-- this element compute the bibtex presentation -->
<apply-external type="xslt" name="XLST32" file="form-bibtex.xsl" in="Y2" out="Y3"/>
<!-- this element remove the abstract and other element in the bibliography
-->
<ruleset type="Internal" name="Rule-Abstract" refOn="stripAbstract" in="D3" out="Z1"/>
<!-- this element sort the biblography by author and year -->
<apply-external type="xslt" name="XLST23" file="sort-ay.xsl" in="Z1" out="Z2"/>
<!-- this element compute the xml presentation -->
<apply-external type="xslt" name="XLST32" file="form-xml.xsl" invv="Z2" out="Z3"/>
</process>
</transmorpher>
|
Figure 1.0 : Complexe XSL process
Figure 2.0: The transformation flow under FlowComposer
bibliography sorted by type
|
bibliography sorted bye date
|
bibliography in bibtex
|
Figure 4.0 : The output
For example :
this description define a complexe transformation
show in figure 1.0
<?xml version="1.0" encoding="UTF-8"?>
<transmorpher xmlns:FM="http://www.fluxmedia.org/schema">
<!-- This sample allow to select a set of elementin the bibliography -->
<process name="mySecondprocess" >
<!-- Read the XML input file -->
<generate type="readfile" name="Reader" out="R1" file="./bibexmo.xml"/>
<!-- Select a set of element : only troncy and brunet reference -->
<query type="simpleOne" name="query1" file="query1.xml" in="R1" out="Z1"/>
<!-- Transform the XML to html -->
<apply-externaltype="xslt" name="XLST32" file="form-xml2html.xsl" in="Z1" out="Z2"/>
<!-- Write the HTML -->
<serialize name="SErializer1" in="Z2" file="Answer.html" />
</process>
</transmorpher>
|
/tr>
<-- This query allow to select all reference of Troncy and Brunet
author -->
<query root="bibliography">
<select expr="bibliography/reference[authors/p/@last='Troncy']"/>
<select expr="bibliography/reference[authors/p/@last='Brunet']"/>
</query>
|
Figure 1.0 : Query sample
this description defines the complex transformation shown in figure 1.0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE transmorpher SYSTEM "../../dtd/transmorpher.dtd">
<transmorpher name="generateBiblio"
xmlns="http://transmorpher.fluxmedia.fr/1.0"
xmlns:regexp="xalan://fr.fluxmedia.transmorpher.regexp.RegularExpression">
<ruleset name="stripAbstract">
<remtag match="abstract" context="reference"/>
<remtag match="keywords" context="reference"/>
<remtag match="areas" context="reference"/>
<remtag match="softwares" context="reference"/>
<remtag match="contracts" context="reference"/>
<remtag match="*[@status='hidden']"/>
<resubst match="conference/@issue" source="([0-9]+)" target="$1e"/>
<rematt match="status"/>
<rematt match="isbn" context="book"/>
</ruleset>
<query name="troncybrunet" type="tmq" root="bibliography">
<select match="bibliography/reference[authors/p/@last='Troncy']"/>
<select match="bibliography/reference[authors/p/@last='Brunet']"/>
</query>
<process name="processGeneral" in="R112" out="X3 Y3 Z3">
<dispatch type="broadcast" id="dispatch 2" in="R112" out="D1 D3"/>
<apply-ruleset ref="stripAbstract" id="StripAbstract" in="D1" out="X1"/>
<dispatch type="broadcast" id="dispatchStripped" in="X1" out="X11 X12"/>
<apply-external type="xslt" id="SortTypeYear" file="biblio/sort-ty.xsl" in="X11" out="X2"/>
<apply-external type="xslt" id="FormatHTML" file="biblio/form-harea.xsl" in="X2" out="X3"/>
<apply-external type="xslt" id="SortCategYear" file="biblio/sort-cya.xsl" in="X12" out="Y2"/>
<apply-external type="xslt" id="FormatBib" file="biblio/form-bibtex.xsl" in="Y2" out="Y3"/>
<apply-external type="xslt" id="FormatXML" file="biblio/xmlverbatimwrapper.xsl" in="D3" out="Z3"/>
</process>
<process name="processByNames" in="R111" out="Z34">
<apply-query type="tmq" ref="troncybrunet" id="FilterTB" in="R111" out="Z34" />
</process>
<main name="ProcessBiblio">
<generate type="readfile" id="bibexmo" out="R1" file="biblio/bibexmo.xml"/>
<generate type="readfile" id="je" out="R2" file="biblio/je.xml"/>
<merge type="concat" id="merge" in="R1 R2" out="R3"/>
<dispatch type="broadcast" id="dispatch1" in="R3" out="X11 X12"/>
<apply-process id="generateFormat" ref="processGeneral" in="X11" out="X31 Y31 Z31" />
<serialize type="writefile" id="writeHTML" in="X31" file="biblio/biblio.html" />
<serialize type="writefile" id="writeBIB" in="Y31" file="biblio/biblio.bib"/>
<serialize type="writefile" id="writeXML" in="Z31" file="biblio/biblio-xml.html"/>
<apply-process id="processTB" ref="processByNames" in="X12" out="W3" />
<serialize type="writefile" id="writeTB" in="W3" file="biblio/biblio_tb.html"/>
</main>
</transmorpher>
|
Figure 1.0 : Complexe XSL process
Figure 2.0 : Complexe XSL process
Figure 3.0 : Complexe XSL process
bibliography sorted by type
|
bibliography sorted bye date
|
bibliography in bibtex
|
Figure 4.0 : The output
These transformations are still used to deliver the bibliographies of the Exmo and mOeX teams.
See performance.
Next chapter: Computational model
Feel free to comment to
Jérôme:Euzenat#inrialpes:fr,
$Id: examples.html,v 1.7 2005-10-25 13:34:00 euzenat Exp $