1 / 3
Feb 2020

That's not a great title..sorry! It's quite hard to explain this one!

Let's say I've got the following XML for a single record (records are split at \ecatalogue\tuple)

<ecatalogue name="ecatalogue">
   <tuple>
      <irn>80489</irn>
      <ColMainTitle>Henning, Ritchie &amp; Hill.</ColMainTitle>
      <ColObjectNumber>ALB-24-70</ColObjectNumber>
      <ColObjectStatus>2- Direct supervision</ColObjectStatus>
      <ConConsObjectType/>
      <EADLevelAttribute/>
      <PhoRecordLevel>Item</PhoRecordLevel>
      <SecRecordStatus>Active</SecRecordStatus>
      <PhoRecordStatus>Complete</PhoRecordStatus>
      <ColArtistNameRef_tab name="ColArtistNameRef_tab">
         <tuple>
            <irn>40</irn>
            <NamFirst/>
            <NamFullName>David Octavius Hill &amp; Robert Adamson</NamFullName>
            <NamLast/>
            <NamTitle/>
            <BioBirthDate>1843</BioBirthDate>
            <BioDeathDate>1847</BioDeathDate>
            <AddPhysCity/>
            <AddPhysCountry/>
            <NamPartyType>Organisation</NamPartyType>
            <NamOrganisation>David Octavius Hill &amp; Robert Adamson</NamOrganisation>
         </tuple>
         <tuple>
            <irn>13609</irn>
            <NamFirst>David</NamFirst>
            <NamFullName>David O. Hill</NamFullName>
            <NamLast>Hill</NamLast>
            <NamTitle/>
            <BioBirthDate>20/May/1802</BioBirthDate>
            <BioDeathDate>1870</BioDeathDate>
            <AddPhysCity/>
            <AddPhysCountry/>
            <NamPartyType>Person</NamPartyType>
            <NamOrganisation>Hill &amp; Adamson</NamOrganisation>
         </tuple>
      </ColArtistNameRef_tab>
   </tuple>
</ecatalogue>

I want to keep the child elements of each ColArtistNameRef_tab tuple together so i can then reference the child elements together within the FTL.

At the moment each child element is mapped to separate classes (i.e BioBirthDate is mapped to "DOB"), but the result is that these child elements are just flattly attached to the returned record. This is a problem when not all the child elements have values, so i can't even reference the index of one list to output the correct position on another list (if that makes sense!!).

Is there a way to map a class to the parent element ColArtistNameRef_tab tuple (/ecatalogue/tuple/ColArtistNameRef_tab/tuple) which groups the child elements to that class, making them usable in FTL?

I.e map "Artist" to "ecatalogue/tuple/ColArtistNameRef_tab/tuple",

then in FTL, do something like this?

<#assign artist = s.result.listMetadata['Artist']!"null"/>

<#list artist as a>
${a.NamFirst} ${a.NamLast}
</#list>

etc

I've tried mapping "ecatalogue/tuple/ColArtistNameRef_tab/tuple" to a class, but it just shows as 0 matching documents. I've also tried some fancier XPATH mapping such as "/ecatalogue/tuple/ColArtistNameRef_tab/child::*" but that also has zero matching documents.

Any advice would be greatly received! Thanks!

  • created

    Feb '20
  • last reply

    Feb '20
  • 2

    replies

  • 3.6k

    views

  • 2

    users

I think basically not without a bunch of work, as it doesn't really have the concept you want. "so i can't even reference the index of one list to output the correct position on another list (if that makes sense!!)." that all makes sense.

Something you could do, to sort of do what you want is write a filter (or do this externally). Take your inner Tuple convert it to a nice bit of JSON and then map that to metdata.

So update your XML to contain (externally or in a filter):

         <json>
{
  &quot;tuple&quot;: {
    &quot;irn&quot;: &quot;40&quot;,
    &quot;NamFullName&quot;: &quot;David Octavius Hill &amp; Robert Adamson&quot;,
    &quot;BioBirthDate&quot;: &quot;1843&quot;,
    &quot;BioDeathDate&quot;: &quot;1847&quot;,
    &quot;NamPartyType&quot;: &quot;Organisation&quot;,
    &quot;NamOrganisation&quot;: &quot;David Octavius Hill &amp; Robert Adamson&quot;
  }
}
         </json>

Note the XML encoding.

Edited metadata mappings and map that new XML element I mapped:

/ecatalogue/tuple/ColArtistNameRef_tab/json

to AsJson.

Re-index and at search.json I could see:

"AsJson": [
"{ \"tuple\": { \"irn\": \"40\", \"NamFullName\": \"David Octavius Hill & Robert Adamson\", \"BioBirthDate\": \"1843\", \"BioDeathDate\": \"1847\", \"NamPartyType\": \"Organisation\", \"NamOrganisation\": \"David Octavius Hill & Robert Adamson\" } } "
]

Apply JSON decoding ( i think you will have to do that either in a hook script or some JS). Then formatting that string gives:

{
   "tuple":{
      "irn":"40",
      "NamFullName":"David Octavius Hill & Robert Adamson",
      "BioBirthDate":"1843",
      "BioDeathDate":"1847",
      "NamPartyType":"Organisation",
      "NamOrganisation":"David Octavius Hill & Robert Adamson"
   
}
}

Note that some changes to white space might be made like double space may be removed, if that is an issue encode spaces in json I think you can do that with \uXXXX. Also be sure to use that \uXXXX thing for any default metadata separators the default being |.

Brilliant thanks Luke! I think I ended up doing something similar.... I already run the XML through an XSLT before it hits funnelback, so I ended up using the XSLT to generate a new field based on various logic if the other fields were empty or not. It seems to work..although i hate doing anything in XSLT so dread having to change it in future!!