I am having an issue getting a repeat to work correctly with an XML structure to create a detail table. In the example below, no matter where I am when I start the repeat it picks up all of the sections.The intent is to get a different detail table for each display_category section.
Any pointers?
Thanks!
Komfort
Acht Lautsprecher (Herstellereigene Marke)
Belüftungssystem mit digitaler Überwachung und Pollenfilter
Sicherheit
4 Scheibenbremsen (2 innenbelüftet)
ABS
Antriebs-Schlupf-Regelung
Außen
Alufelgen 8,0 X 17 auf Vorderachse und Hinterachse
Stoßfänger in Wagenfarbe und vorn, Stoßfänger lackiert und hinten
Technik
6-Gang Schaltgetriebe manuell
Kraftstoff : Diesel
Kraftstoffsystem mit Common Rail
I think this is a perfect use case for the new Multiple Condition step in the Datamapper. Your Repeat step should occur on each <display_category> element. Then, inside the loop, add a multiple condition and add as many Cases as there are possible display categories. In each Case branch, add an Extract step that fills the appropriate Detail table.
First, recall that you don’t have to create the tables in the right pane, you can do so directly in the Extraction Definition section of the Extract Step’s properties panel. By default, inside a loop, the Data Table setting will be set to record.details, but you can simply rename it to record.komfort, record.sicherheit, etc. This will immediately add those tables to the Data Model pane.
Now depending on what you actually want to extract, you could have another loop inside each branch in order to extract all <beschreibung> elements, But for the sake of simplicity, I think you could simply set your overall Repeat step to loop on All elements (Use a For Each type and select the ./following::* Collection) then inside that loop, examine each element name, determine which <display_category> you’re dealing with, then extract all <beschreibung> elements until you hit a different category.
I almost have it working but I am not getting any items in the tables. How exactly does the //following::* collection work? When I use that it selects the entire XML file for the repeat. (My fault - I did not originally share the entire structure!). The section I gave you as an example is actually a few nodes in in the structure. So, I was wondering if that collection could be used starting at Serienausstattung. The file looks like(Serienausstattung is the third node in):
Komfort
Acht Lautsprecher (Herstellereigene Marke)
Sicherheit
2 höhenverstellbare Kopfstützen vorne, 3
Außen
Alufelgen 8,0 X 17 auf Vorderachse und Hinterachse
Technik
6-Gang Schaltgetriebe manuell
TEST
Multifunktions-Lederlenkrad im 4-Speichen-Design
151.260000
Well, I got part of it. If I change //following::* to ./Angebot_Kopf/Serienausstattung//following::* then the repeat does not start till the Serienausstattung node. However, it goes to the end of the file from there. Now I need to get it to stop when it hits the next node - in this case .
Awesome! That seems to work. Where can I find more info on the XPATH syntax?
I am assuming that the Data Model pane on the right will not show any values because the extraction has not run? Is there a way to step thru to prove that these tables get populated?
For a basic XPATH tutorial that covers most of what you will ever need in the DataMapper, you can try this W3Schools tutorial, in particular the XPATH Axes section.
As for the DataModel, it should always show you the results of the extraction for the current record. If you don’t have anything in there it means the extraction didn’t work properly. Check out the Messages panel to see if there are any warnings or errors reported.
Send the Data Mapping config instead. The DataModel can’t tell me what’s wrong with the extraction process, it just lists the structure of what your attempting to extract…
Just a small error in the Config, the first Multiple Condition was comparing an empty value with the name of the element it was inspecting. It may have been something I overlooked when I initially sent you the config or maybe you changed it inadvertently.
In any event, I fixed it and it works fine. I am attaching a package file (containing both the revised DM Config and a basic Template). Just open the package in the Designer, both resources will be loaded and you can see the results by yourself: https://learn.objectiflune.com/qa-blobs/13691392376432887205.ol-package
That makes sense. This is perfect! You have definitely taught me a lot here. Also - thanks for the link to the tutorial. I guess that will give me some weekend work
I am assuming that I can change the column headings that come over in the template to something more relevant. Wouldn’t want all 4 tables to have the same heading!
Yes of course. Simply click on the headers, edit to your liking, and you’re done. The match between the column contents and the data is not performed on the Header name of the column but rather on the class or element attributes, so there’s no danger of losing the link between both when renaming headers.