Loop Extraction without detail table

Hello there !
I’m new to the tool and I have been looking through documentation and tutorials for a while now, but I can’t find a way to achieve what I want.
It seems pretty basic to me tho, so I guess I probably missed something important in the doc.
So I have a XML file which has a common structure that I would sum up as follows :
<metaTag>
<firstTag>
<tag_A>...</tag_A>
<tag_A>...</tag_A>
<tag_A>...</tag_A>

</firstTag>
<secondTag>
<tag_A>...</tag_A>
<tag_A>...</tag_A>
<tag_A>...</tag_A>

</secondTag>
</metaTag>
I only know that number of <tag_A> cannot exceed 10 within </firstTag> and 20 within </secondTag> , but is supposed undetermined so I proceed to loop extractions (ForEach type) and everything goes well, it’s getting stored in a detail table. No problem, I thought, that’s a clean way to work.

But the thing is, it looks like details can only be displayed as tables in the designer… and I really don’t want that, because of the various types of informations contained inside of the <tag_A> which are to be displayed in very different places of the document, depending on their parent tag.

So, my first question would have been : How do you get the value of a field inside of a detail table ? And I found the answer in the doc : you can’t. Ok. But then, how should I proceed to just get the values anyway ?
If I try to store the result of those loops directly in the record and not within a detail table, then I don’t have a way to dynamically differenciate the <tag_A> coming from </firstTag> and those coming from </secondTag> ; if I try to do the trick by creating two different fields to store them and use XPATH, I just get the “Can’t be extracted twice” error.
Is there a way to achieve this ? Also, I can’t modify the structure of the XML file, as it’s a standardized flux.

Thanks for your time, also I’m sorry for the poor XML formatting in the post I did not find how to make it cleaner than that, and for english as it’s not my native language !
Best regards.

Hi @MrD,

Welcome on our OL Learn forum!

Can you let us know please if you would like to create one detail table of all tag_A nodes which does exist in the child node of the metaTag node or if you would like to create a detail table for the first child node of the metaTag node and a second detail table for the second child node of the metaTag node and so on?

In case it is the first part then I would like to let you know that you can use a Repeat Step to loop through the child nodes of the metaTag node, by using the following Step Properties for example:

Repeat definition:

  • Repeat type: [For Each]
  • Maximum iterations on each line: [1;]
  • [Unchecked] No Goto step required
  • Collection: [./*]

And then place a Repeat Step inside the above Repeat Step and use the following settings to loop through each tag_A node:

Repeat definition:

  • Repeat type: [For Each]
  • Maximum iterations on each line: [1;]
  • [Unchecked] No Goto step required
  • Collection: [./tag_A]

And then you can extract the data of tag_A by placing a Extract Step inside the second Repeat Step and use settings like the following for example:

Field definition:

  • Field List [tag_A]
  • Based on: [Location]
  • XPath: [.]
  • Trim: [Both]
  • Type: [String]

The (Steps) result will look something like:

example_20220419


I’ve used the following XML to test the above described settings:

<?xml version="1.0" encoding="UTF-8"?>
<metaTag>
	<firstTag>
		<tag_A>test 1</tag_A>
		<tag_A>test 2</tag_A>
		<tag_A>test 3</tag_A>
	</firstTag>
	<secondTag>
		<tag_A>test 4</tag_A>
		<tag_A>test 5</tag_A>
		<tag_A>test 6</tag_A>
	</secondTag>
</metaTag>

Hey, thanks for your quick answer !
Unfortunately, I’m in the second case. But, in fact, making the extractions steps is not really what bothers me, maybe I didn’t make it really clear.

I indeed managed to create two different detail tables, one containing the tag_A datas of firstTag and the other containing those of secondTag. Now, the thing is that it seems to me that I can’t use those datas the way I want.
Lets take the XML you made, so I have 2 details tables : one contains test 1, test 2, test 3 and the other contains test 4, test 5, test 6. Well in the designer, I can’t, for example, drag’n’drop test 1 from the data model on top of the page, then test 2 as a footer, and make these appear as a regular field (i.e a field which is not contained in a detail table). If I try, i’ll get the pop-up message “impossible to insert text in nested detail tables fields. Do you want to open the Dynamic table Wizard ?” (translated from french so maybe not 100% accurate).

Therefore, I seem to be forced to include the value “test 1” inside an HTML table, which is not a suitable solution for what I want to design because the “test” datas are not supposed do be displayed in a table at all…

I also tried getting the value of a detail table field “manually” by adding a hard coded JS script that would get it from the data model, but failed.

Knowing all that, my question is/are : is there a way to get a dynamic number of datas out from this kind of XML structures without using detail tables ; or : is there a way to get the values of detail tables fields without displaying it as a table in the created template.

Again, thanks a lot !

I assume that you can solve this by making use of some JavaScript code on the Template side.

Let’s say that you are adding all existing nested tag_A nodes to a detail table on the Data Mapping Configuration side but that you would like to assign only the value of the third tag_A (detail table) field to a HTML element on the Template side, then you can use for example HTML code like:

<p>
	Example: <span id="example">@Example@</span>
</p>

…and a Standard Script like:

  • Name: Example
  • Selector: #example
var result = "";

if ("example" in record.tables && record.tables.length >= 3) {
	result = record.tables["example"].fields["tagA"];
}

results.html(result);

…to assign the value of the third tag_A (detail table) field to a HTML element.

1 Like

Well, that’s exactly what I tried in the first place ! And I had the error : “impossible to read the “tagA” property of undefined” (and I think this code would have it too, lol).

BUT, thanks to your reply, I managed to find out that I’ve been misunderstanding the depth of the detail tables, and now it works ! Simply by adding the iteration index, just like in every other language :

var result = "";
if ("example" in record.tables && record.tables.length >= 3) {
result = record.tables["example"][2].fields["tagA"];
}
results.html(result);

to get the 3rd value.
I was mixing up two different problems in my head because of the structure of my XML which is more complex than that.
Anyway, your reply took me to the solution, so thank you very much ! :slight_smile:

Hi @MrD,

You’re totally right. My mistake, I forgot to add the index value to the record.tables["example"] JavaScript code. The earlier shared JavaScript code should be:

var result = "";

if ("example" in record.tables && record.tables.length >= 3) {
	result = record.tables["example"][2].fields["tagA"];
}

results.html(result);

Anyway, your reply took me to the solution, so thank you very much ! :slight_smile:

You are welcome!

1 Like