-
Notifications
You must be signed in to change notification settings - Fork 34
Metamorph Cookbook
Please add recipes under 'Solutions'. If you have a problem in need of a solution, please add it under 'Open Problems'.
The following sections present solutions to common problems.
If A happens only once and before Bs:
<combine name="" value="${a}" reset="false">
<data source="A" name="a"/>
<data source="B" name=""/>
</combine>
if A happens only once but after Bs, the Bs must be delayed by buffering them:
<combine name="" value="${a}" reset="false">
<data source="A" name="a"/>
<data source="B" name="">
<buffer/>
</data>
</combine>
Four lines of text should be extracted from a pica+ record which all begin with the $f-subfield of the 003@ and are followed by a combination of subfields in each 028@.
003@ ƒ01025201213
028@ ƒdFarīdƒcal-ƒaʿAbdalāwī
028@ ƒdFarīdƒaAl-ʿAbdalāwī
028@ ƒdFarid HamidƒaEl Abdellaouiƒ4nawi
028@ ƒdFarid HamidƒaAbdellaouiƒlEl
The rule of metamorph is defined as:
<combine name="${personalname}${surname}${forename}${prefix}${addition}"
value="##${pid}##,##${personalname}${surname}${forename}${prefix}${addition}##,##V##"
flushWith="028@" reset="true">
<data source="[email protected]" name="pid"/>
<data source="[email protected]" name="personalname" />
<data source="[email protected]" name="surname"/>
<data source="[email protected]" name="forename"/>
<data source="[email protected]" name="prefix"/>
<concat name="addition" delimiter=", " flushWith="028@" reset="true" prefix=" ">
<data source="[email protected]"/>
<data source="[email protected]"/>
<data source="[email protected]"/>
</concat>
</combine>
The following output is expected:
'##1025201213##,##Abdellaoui, Farid Hamid##,##V##'
'##1025201213##,##Al-ʿAbdalāwī, Farīd##,##V##'
'##1025201213##,##El Abdellaoui, Farid Hamid##,##V##'
'##1025201213##,##ʿAbdalāwī, Farīd al-##,##V##'
In fact output looks like this:
'##1025201213##,##Abdellaoui, Farid Hamid##,##V##'
'####,##Al-ʿAbdalāwī, Farīd##,##V##'
'####,##El Abdellaoui, Farid Hamid##,##V##'
'####,##ʿAbdalāwī, Farīd al-##,##V##'
The reset=”true” option cleans the 003@ and 028@ before a new 028@ is read. A new 003@ doesn’t exist and it is therefore empty. Neither reset=”false” can be used here, because it will remember the value of the old 028@, like the “al-“ at end of the following lines which in fact only appears in the first 028@ field.
'##1025201213##,##Abdellaoui, Farid Hamid al-##,##V##'
'##1025201213##,##Al-ʿAbdalāwī, Farīd al-##,##V##'
'##1025201213##,##El Abdellaoui, Farid Hamid al-##,##V##'
'##1025201213##,##ʿAbdalāwī, Farīd al-##,##V##'
The solution is use of recursion (prefix @):
<combine name="@pid" value="${pid}" flushWith="028@">
<data source="[email protected]" name="pid"/>
</combine>
<combine name="${personalname}${surname}${forename}${prefix}${addition}"
value="##${pid}##,##${personalname}${surname}${forename}${prefix}${addition}##,##V##"
flushWith="028@" reset="true">
<data source="@pid" name="pid"/>
<data source="[email protected]" name="personalname" />
<data source="[email protected]" name="surname"/>
<data source="[email protected]" name="forename"/>
<data source="[email protected]" name="prefix"/>
<concat name="addition" delimiter=", " flushWith="028A" reset="true" prefix=" ">
<data source="[email protected]"/>
<data source="[email protected]"/>
<data source="[email protected]"/>
</concat>
</combine>
The first <combine>
element use the name “@pid” to declare a redirecting the value return to the input stream and it is done for each new 028@. The second <combine>
element uses the redirected, but not reset value of 003@ to combine the new 028@ values which are reset before read.