Overview
Selecting nodes
Inserting nodes
Replacing nodes
Removing nodes
Merging nodes
Aggregating nodes
Moving nodes
Joining data views
<library> <video id="V1" type="movie" date="2003" genre="horror" title="Freddy vs. Jason"></video> <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"> <details> <country>United States</country> <director>Tom Holland</director> <producer>David Kirschner</producer> </details> </video> <video id="V3" type="movie" date="1985" genre="comedy" title="The Purple Rose of Cairo"></video> <video id="V4" type="documentary" date="2007" genre="music" title="Joe Strummer: The Future Is Unwritten"></video> <book id="B1" type="" title="The Flowers of Evil"></book> <book id="B2" type="IT" date="2001" title="Learning XML"></book> </library>
<processors> <processor match="/library/video[@title='Bride of Chucky']" type="SelectProcessor"/> </processors>
<e:entries xmlns:e="http://software.in2p3.fr/lavoisier/entries.xsd"> <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"> <details> <country>United States</country> <director>Tom Holland</director> <producer>David Kirschner</producer> </details> </video> </e:entries>
Notice: the output is automatically encapsulated by entries tag to ensure XML format validity if the result is composed of multiple node-set. You can avoid this behaviour setting the parameter 'single_node' to 'true' :
<processor match="/library/video[@title='Bride of Chucky']" type="SelectProcessor"> <parameter name="single_node">true</parameter> </processor>
<processors> <processor match="/library/video" type="SelectProcessor"> <parameter name="depth">1</parameter> </processor> </processors>
<e:entries xmlns:e="http://software.in2p3.fr/lavoisier/entries.xsd"> <video id="V1" type="movie" date="2003" genre="horror" title="Freddy vs. Jason"></video> <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"></video> <video id="V3" type="movie" date="1985" genre="comedy" title="The Purple Rose of Cairo"></video> <video id="V4" type="documentary" date="2007" genre="music" title="Joe Strummer: The Future Is Unwritten"></video> </e:entries>
<processors> <processor match="/library/*/@genre" type="SelectDistinctProcessor"> <parameter name="sort_type">text</parameter> <parameter name="sort_descending">true</parameter> </processor> </processors>
<e:entries xmlns:e="http://software.in2p3.fr/lavoisier/entries.xsd"> <e:entry key="music"></e:entry> <e:entry key="horror"></e:entry> <e:entry key="comedy"></e:entry> </e:entries>
<processors> <processor match="/library/*/@genre" type="SelectDistinctProcessor"> <parameter name="sort_type">text</parameter> <parameter name="sort_descending">true</parameter> </processor> <processor type="ChangeNamespaceProcessor" match="//*"/> </processors>
<entries> <entry key="music"></entry> <entry key="horror"></entry> <entry key="comedy"></entry> </entries>
<processors> <processor match="/library/book[@title='Learning XML']" type="InsertProcessor"> <parameter name="nodes" eval="new_attribute('author', 'Erik T. Ray')"/> </processor> </processors>
<library> ... ... ... ... ... <book id="B2" type="IT" date="2001" title="Learning XML" author="Erik T. Ray"></book> </library>
<processors> <processor match="/library/*[@genre]" type="InsertProcessor"> <parameter name="destination_as">first_child</parameter> <parameter name="nodes" eval="new_element('description', concat(@type, ' ', @genre))"/> </processor> </processors>
<library> <video id="V1" type="movie" date="2003" genre="horror" title="Freddy vs. Jason"> <description>movie horror</description> </video> <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"> <description> horror</description> <details> <country>United States</country> <director>Tom Holland</director> <producer>David Kirschner</producer> </details> </video> <video id="V3" type="movie" date="1985" genre="comedy" title="The Purple Rose of Cairo"> <description>movie comedy</description> </video> <video id="V4" type="documentary" date="2007" genre="music" title="Joe Strummer: The Future Is Unwritten"> <description>documentary music</description> </video> <book id="B1" type="" title="The Flowers of Evil"></book> <book id="B2" type="IT" date="2001" title="Learning XML"></book> </library>
<processors> <processor match="/library/book" type="InsertParentProcessor"> <parameter name="node_name">books</parameter> </processor> </processors>
<library> ... ... <video id="V3" type="movie" date="1985" genre="comedy" title="The Purple Rose of Cairo"></video> <video id="V4" type="documentary" date="2007" genre="music" title="Joe Strummer: The Future Is Unwritten"></video> <books> <book id="B1" type="" title="The Flowers of Evil"></book> <book id="B2" type="IT" date="2001" title="Learning XML"></book> </books> </library>
Notice: This will group together all subsequent <book> elements.
<library_details> <details id="V1"> <country>United States</country> <director>Ronny Yu</director> <producer>Sean S. Cunningham, Douglas Curtis, Stokely Chaffin, Robert Shaye et Renee Witt</producer> </details> <details id="V3"> <country>United States</country> <director>Woody Allen</director> <producer>Robert Greenhut</producer> </details> <details id="V4"> <director>Julien Temple</director> </details> <details id="B1"> <country>France</country> <editor>Larousse</editor> <author>Charles Baudelaire</author> </details> <details id="B2"> <country>United States</country> <editor>O'Reilly</editor> </details> </library_details>
<processors> <processor match="/library/*" type="InsertProcessor"> <parameter name="nodes" eval="view_path_post('insert_join_0', choose(path(false()), path(false()), ''), match(), arguments())"/> </processor> </processors>
<library> <video id="V1" type="movie" date="2003" genre="horror" title="Freddy vs. Jason"> <details id="V1"> <country>United States</country> <director>Ronny Yu</director> <producer>Sean S. Cunningham, Douglas Curtis, Stokely Chaffin, Robert Shaye et Renee Witt</producer> </details> </video> <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"> <details> <country>United States</country> <director>Tom Holland</director> <producer>David Kirschner</producer> </details> </video> <video id="V3" type="movie" date="1985" genre="comedy" title="The Purple Rose of Cairo"> <details id="V3"> <country>United States</country> <director>Woody Allen</director> <producer>Robert Greenhut</producer> </details> </video> <video id="V4" type="documentary" date="2007" genre="music" title="Joe Strummer: The Future Is Unwritten"> <details id="V4"> <director>Julien Temple</director> </details> </video> <book id="B1" type="" title="The Flowers of Evil"> <details id="B1"> <country>France</country> <editor>Larousse</editor> <author>Charles Baudelaire</author> </details> </book> <book id="B2" type="IT" date="2001" title="Learning XML"> <details id="B2"> <country>United States</country> <editor>O'Reilly</editor> </details> </book> </library>
<processors> <processor match="/library/*/@type[.='']" type="ReplaceProcessor"> <parameter name="nodes" eval="'not available'"/> </processor> </processors>
<library> <video id="V1" type="movie" date="2003" genre="horror" title="Freddy vs. Jason"></video> <video id="V2" type="not available" date="1998" genre="horror" title="Bride of Chucky"> <details> <country>United States</country> <director>Tom Holland</director> <producer>David Kirschner</producer> </details> </video> ... ... <book id="B1" type="not available" title="The Flowers of Evil"></book> <book id="B2" type="IT" date="2001" title="Learning XML"></book> </library>
<processors> <!-- *Example 1 :* remove all items where attribute @genre is not present --> <processor match="/library/*[not(@genre)]" type="RemoveProcessor"/> <!-- *Example 2 :* remove element <details> but not its content --> <processor match="/library/*/details" type="RemoveProcessor"> <parameter name="depth">1</parameter> </processor> </processors>
<library> <video id="V1" type="movie" date="2003" genre="horror" title="Freddy vs. Jason"></video> <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"> <country>United States</country> <director>Tom Holland</director> <producer>David Kirschner</producer> </video> <video id="V3" type="movie" date="1985" genre="comedy" title="The Purple Rose of Cairo"></video> <video id="V4" type="documentary" date="2007" genre="music" title="Joe Strummer: The Future Is Unwritten"></video> </library>
<processors> <processor match="/library/video/details/country" type="MergeProcessor"/> </processors>
<library> ... <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"> <details> <country country="United States"></country> <director>Tom Holland</director> <producer>David Kirschner</producer> </details> </video> ... ... ... ... </library>
<processors> <!-- first merge ALL text nodes of children of <details> node, then move them to attributes : ex <producer producer="David Kirschner"/>--> <processor match="/library/video/details/*" type="MergeProcessor"/> <!-- Then merge <details> node with children --> <processor match="/library/video/details" type="MultiMergeProcessor"> <parameter name="count">4</parameter> </processor> </processors>
<library> <video id="V1" type="movie" date="2003" genre="horror" title="Freddy vs. Jason"></video> <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"> <details country="United States" director="Tom Holland" producer="David Kirschner"></details> </video> ... ... ... ... </library>
<processors> <processor match="/library" type="AppendAggregateProcessor"> <parameter name="function">count</parameter> <parameter name="node_name">XXst_century</parameter> <parameter name="node_values" eval="*[substring(@date, 1, 2)='19']"/> </processor> </processors>
<library> ... ... ... ... ... ... <XXst_century>2.0</XXst_century> </library>
Notice: You can notice that the result is at the end of the context, a constraint of sreaming processes.
An aggregate function is a function where the values of multiple rows are grouped together as input on certain criteria to form a single value of more significant meaning or measurement such as a set, a bag or a list.(src: Wikipedia). Aggregate processor can be used with the following functions : avg, count, max, min, sum<processors> <processor match="/library/video" type="MoveProcessor"> <parameter name="destination_axis">following-sibling</parameter> <parameter name="destination_name">book</parameter> <parameter name="destination_predicate" eval="@id='B1'"/> <parameter name="destination_as">following_sibling</parameter> </processor> </processors>
<library> <book id="B1" type="" title="The Flowers of Evil"></book> <video id="V1" type="movie" date="2003" genre="horror" title="Freddy vs. Jason"></video> <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"> <details> <country>United States</country> <director>Tom Holland</director> <producer>David Kirschner</producer> </details> </video> <video id="V3" type="movie" date="1985" genre="comedy" title="The Purple Rose of Cairo"></video> <video id="V4" type="documentary" date="2007" genre="music" title="Joe Strummer: The Future Is Unwritten"></video> <book id="B2" type="IT" date="2001" title="Learning XML"></book> </library>
<processors> <processor match="/library/video" type="MoveProcessor"> <parameter name="destination_axis">ancestor</parameter> <parameter name="destination_name">library</parameter> <parameter name="destination_as">last_child</parameter> </processor> </processors>
<library> <book id="B1" type="" title="The Flowers of Evil"></book> <book id="B2" type="IT" date="2001" title="Learning XML"></book> <video id="V1" type="movie" date="2003" genre="horror" title="Freddy vs. Jason"></video> <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"> <details> <country>United States</country> <director>Tom Holland</director> <producer>David Kirschner</producer> </details> </video> <video id="V3" type="movie" date="1985" genre="comedy" title="The Purple Rose of Cairo"></video> <video id="V4" type="documentary" date="2007" genre="music" title="Joe Strummer: The Future Is Unwritten"></video> </library>
<processors> <processor match="/library" type="InsertProcessor"> <parameter name="destination_as">last_child</parameter> <parameter name="nodes" eval="new_element('books')"/> </processor> <processor match="/library/book" type="MoveProcessor"> <parameter name="destination_axis">following-sibling</parameter> <parameter name="destination_name">books</parameter> </processor> </processors>
<library> ... ... ... ... <books> <book id="B1" type="" title="The Flowers of Evil"></book> <book id="B2" type="IT" date="2001" title="Learning XML"></book> </books> </library>
Notice: if <book> elements are subsequent then prefer using <insert> processor instead of <move> as described in Example 3 of <insert> documentation. It would be more efficient.
<processors> <processor match="/library/video/details/*" type="MoveProcessor"> <parameter name="destination_axis">ancestor</parameter> <parameter name="destination_name">video</parameter> </processor> </processors>
<library> <video id="V1" type="movie" date="2003" genre="horror" title="Freddy vs. Jason"></video> <video id="V2" type="" date="1998" genre="horror" title="Bride of Chucky"> <details> </details> <country>United States</country> <director>Tom Holland</director> <producer>David Kirschner</producer> </video> ... ... ... ... </library>
The data view to be joined in the examples below are defined as follow.
View VA:<result> <row><HOST>h1</HOST><PATH>p1</PATH><RATE>r1</RATE></row> <row><HOST>h2</HOST><PATH>p2</PATH><RATE>r2</RATE></row> </result>
<result> <row><HOST>h1</HOST><PATH>p1</PATH><NB>n1</NB></row> <row><HOST>h1</HOST><PATH>p1</PATH><NB>n1_bis</NB></row> <row><HOST>h3</HOST><PATH>p3</PATH><NB>n3</NB></row> </result>
All the solution proposed in this section generate the same output data:
<e:entries xmlns:e="http://software.in2p3.fr/lavoisier/entries.xsd"> <row> <HOST>h1</HOST> <PATH>p1</PATH> <NB>n1</NB> <RATE>r1</RATE> </row> <row> <HOST>h1</HOST> <PATH>p1</PATH> <NB>n1_bis</NB> <RATE>r1</RATE> </row> </e:entries>
<processors> <processor match="/result/row[*]" type="InsertProcessor"> <parameter name="nodes" eval="view_path_post('join_1_0', choose(path(false()), path(false()), ''), match(), arguments())"/> </processor> <processor match="/result/row/e:entries/row" type="SelectProcessor"/> </processors>
<processors> <processor match="/result/row[*]" type="InsertProcessor"> <parameter name="nodes" eval="view_path_post('join_2_0', choose(path(false()), path(false()), ''), match(), arguments())"/> </processor> <processor match="/result/row/e:entries/row" type="SelectProcessor"/> </processors>
<processors> <processor match="/result/row[*]" type="InsertProcessor"> <parameter name="nodes" eval="view_path_post('join_3_0', choose(path(false()), path(false()), ''), match(), arguments())"/> </processor> <processor match="/result/row/e:entries/row" type="SelectProcessor"/> </processors>
<processors> <processor match="/result/row[*]" type="InsertProcessor"> <parameter name="nodes" eval="view('VB')/result/row[HOST=match()/HOST and PATH=match()/PATH]"/> </processor> <processor match="/result/row/*[not(self::row)]" type="MergeProcessor"/> <processor match="/result/row" type="MultiMergeProcessor"> <parameter name="count">3</parameter> </processor> <processor match="/result/row/row" type="InsertProcessor"> <parameter name="nodes" eval="new_element('RATE', new_text(parent::row/@RATE))"/> </processor> <processor match="/result/row/row" type="SelectProcessor"/> </processors>