Overview
Selecting nodes with short notation
Inserting nodes with short notation
Replacing nodes with short notation
Removing nodes with short notation
Merging nodes with short notation
Aggregating nodes with short notation
Moving nodes with short notation
Joining data views with short notation
<processors> <!-- standard notation --> <processor type="SelectProcessor" match="/library/video[@title='Bride of Chucky']"> <parameter name="single_node">true</parameter> </processor> <!-- short notation --> <select match="/library/video[@title='Bride of Chucky']" single="true"></select> </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</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 xmlns="http://software.in2p3.fr/lavoisier/config.xsd"> <select match="/absolute/xpath" depth="UNBOUNDED|1..N" single="FALSE|true"> <group by="{relative/xpath}" sort="UNSORTED|text|number|date" descending="FALSE|true"></group> <!-- @match MUST BE a string (attribute, text or comment) --> <distinct sort="UNSORTED|text|number|date" descending="FALSE|true"></distinct> </select> <remove match="/absolute/xpath" depth="UNBOUNDED|1..N"></remove> <insert match="/absolute/xpath" nodes="relative/xpath" as="LAST-CHILD|first-child|preceding-sibling|following-sibling|attribute"> <connector type=""></connector> <serializer type=""></serializer> <processors></processors> </insert> <replace match="/absolute/xpath" nodes="relative/xpath"> <connector type=""></connector> <serializer type=""></serializer> <processors></processors> </replace> <rename match="/absolute/xpath" name="{qualified_name}"></rename> <insert-parent match="/absolute/xpath" name="{qualified_name}"></insert-parent> <move match="/absolute/xpath"> <to-following-sibling name="*|{qualified_name}" predicate="NULL|{predicate}" as="LAST-CHILD|first-child|preceding-sibling|following-sibling|attribute"></to-following-sibling> <to-ancestor name="*|{qualified_name}" predicate="NULL|{predicate}" as="LAST-CHILD|following-sibling"></to-ancestor> </move> <aggregate match="/absolute/xpath" function="COUNT|sum|avg|min|max"><!-- as="last-child" --> <to-last-child name="{qualified_name}" values="relative/xpath"></to-last-child> </aggregate> <merge match="/absolute/xpath"></merge> </processors>
<processors> <select match="/library/video[@title='Bride of Chucky']"></select> </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 encapuslated by entries tag to ensure XML format validity
if the result is composed of mutltiple node-set.
You can avoid this behaviour setting single attribute to 'true' :
<select match="/library/video[@title='Bride of Chucky']" single="true"></select> |
<processors> <select match="/library/video" depth="1"></select> </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> <select match="/library/*/@genre"> <distinct sort="text" descending="true"></distinct> </select> </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> <select match="/library/*/@genre"> <distinct sort="text" descending="true"></distinct> </select> <processor type="ChangeNamespaceProcessor" match="//*"></processor> </processors>
<entries> <entry key="music"></entry> <entry key="horror"></entry> <entry key="comedy"></entry> </entries>
<processors> <insert match="/library/book[@title='Learning XML']" nodes="new_attribute('author', 'Erik T. Ray')"></insert> </processors>
<library> ... ... ... ... ... <book id="B2" type="IT" date="2001" title="Learning XML" author="Erik T. Ray"></book> </library>
<processors> <insert match="/library/*[@genre]" as="first_child" nodes="new_element('description', concat(@type, ' ', @genre))"></insert> </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> <insert-parent match="/library/book" name="books"></insert-parent> </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> <insert match="/library/*"> <connector type="XMLConnector"> <parameter name="content" eval="document('input/library_details.xml')"></parameter> </connector> <processors> <select match="/library_details/details[@id=parent_match()/@id]" single="true"></select> </processors> </insert> </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> <replace match="/library/*/@type[.='']" nodes="'not available'"></replace> </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 --> <remove match="/library/*[not(@genre)]"></remove> <!-- *Example 2 :* remove element <details> but not its content --> <remove match="/library/*/details" depth="1"></remove> </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> <merge match="/library/video/details/country"></merge> </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"/>--> <merge match="/library/video/details/*"></merge> <!-- Then merge <details> node with children --> <merge match="/library/video/details" count="4"></merge> </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> <aggregate match="/library" function="count"> <to-last-child name="XXst_century" values="*[substring(@date, 1, 2)='19']"></to-last-child> </aggregate> </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. |
<processors> <move match="/library/video"> <to-following-sibling name="book" predicate="@id='B1'" as="following_sibling"></to-following-sibling> </move> </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> <move match="/library/video"> <to-ancestor name="library" as="last_child"></to-ancestor> </move> </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> <insert match="/library" as="last_child" nodes="new_element('books')"></insert> <move match="/library/book"> <!-- REM : as="last_child" is the default, you can also write : <to-following-sibling name="books" as="last_child"/> --> <to-following-sibling name="books"></to-following-sibling> </move> </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> <move match="/library/video/details/*"> <to-ancestor name="video"></to-ancestor> </move> </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> <insert match="/result/row[*]"> <connector type="XMLConnector"> <parameter name="content" eval="view('VB')"></parameter> </connector> <processors> <select match="/result/row[HOST=parent_match()/HOST and PATH=parent_match()/PATH]"></select> <insert match="/e:entries/row" nodes="parent_match()/RATE"></insert> </processors> </insert> <select match="/result/row/e:entries/row"></select> </processors>
<processors> <insert match="/result/row[*]"> <connector type="XMLConnector"> <parameter name="content" eval="view_path('VB', concat('/result/row[HOST=',quot(parent_match()/HOST),' and PATH=',quot(parent_match()/PATH),']'))"></parameter> </connector> <processors> <insert match="/e:entries/row" nodes="parent_match()/RATE"></insert> </processors> </insert> <select match="/result/row/e:entries/row"></select> </processors>
<processors> <insert match="/result/row[*]"> <connector type="XMLConnector"> <parameter name="content" eval="new_element('e:entries', view('VB')/result/row[HOST=parent_match()/HOST and PATH=parent_match()/PATH])"></parameter> </connector> <processors> <insert match="/e:entries/row" nodes="parent_match()/RATE"></insert> </processors> </insert> <select match="/result/row/e:entries/row"></select> </processors>
<processors> <insert match="/result/row[*]" nodes="view('VB')/result/row[HOST=match()/HOST and PATH=match()/PATH]"></insert> <merge match="/result/row/*[not(self::row)]"></merge> <merge match="/result/row" count="3"></merge> <insert match="/result/row/row" nodes="new_element('RATE', new_text(parent::row/@RATE))"></insert> <select match="/result/row/row"></select> </processors>