Multi-value elements

In this post, we will learn:

Introduction

In XML feeds, we may encounter elements with identical names. This is not an error, it may be a so-called multi-value element. Multi-value elements allow us to list multiple related values in a feed without having to create a special element for each one. Let’s explain what exactly such a multi-value element is, how to recognize it and how MERGADO Editor allows us to work with such elements.

image

What is a multi-value element?

A multi-value element is an element for which there is a value with position greater than one (even an empty value counts). That is, an element for which the condition { @@POSITION = 2 } can be written.

:information_source:   MERGADO 1 did not work with multi-value elements at all.

What if an element is not multi-value?

If an element is not multi-value, i.e. has only one value (with position equal to one: { @@POSITION = 1 }), we call the element simple.

:information_source:  For simple elements, the position of the value is always equal to 1 and does not need to be written in path.

Let’s explain the difference between multi-value and simple elements with examples.

Examples

Example 1

<IMGURL_ALTERNATIVE>url1</IMGURL_ALTERNATIVE>
<IMGURL_ALTERNATIVE>url2</IMGURL_ALTERNATIVE>

This is a multi-value element, because the IMGURL_ALTERNATIVE element has a url2 value with position greater than one: IMGURL_ALTERNATIVE { @@POSITION = 2 }.
 
Example 2

<IMAGE1>url1</IMAGE1>
<IMAGE2>url2</IMAGE2>

This is not a mutli-value element, but 2 simple elements IMAGE1 and IMAGE2. The IMAGE1 element is different from IMAGE2. In fact, both elements have just one value (both with position equal to one).

The path for the url1 value is IMAGE1 { @@POSITION = 1 } and for the url2 value is IMAGE2 { @@POSITION = 1 }. And since we know that the part with @@POSITION = 1 is not necessary to write, we truncate the paths to IMAGE1 and IMAGE2.
 
Example 3

<IMAGES>
    <IMAGE>url1</IMAGE>
    <IMAGE>url2</IMAGE>
</IMAGES>

In this case, the IMAGES element is not a multi-value element, but IMAGE is a multi-value element. Because the IMAGE element has a value for the path IMAGES | IMAGE { @@POSITION = 2 }, that is, the IMAGE element has more than one value for a product and the IMAGES element has only one value (and it is empty).
 
Example 4

<PARAM>
    <PARAM_NAME>Color</PARAM_NAME>
    <VAL>black</VAL>
</PARAM>
<PARAM>
    <PARAM_NAME>Weight</PARAM_NAME>
    <VAL>90g</VAL>
</PARAM>

The PARAM element is multi-value since it has two values (empty) and at the same time the PARAM_NAME and VAL elements are not multi-value. This may be surprising since it looks like both elements have two values. But the paths for each value look like this:

  1. PARAM { @@POSITION = 1 } | PARAM_NAME { @@POSITION = 1 }
  2. PARAM { @@POSITION = 1 } | VAL { @@POSITION = 1 }
  3. PARAM { @@POSITION = 2 } | PARAM_NAME { @@POSITION = 1 }
  4. PARAM { @@POSITION = 2 } | VAL { @@POSITION = 1 }

Thus, the PARAM_NAME and VAL elements have multiple values, but they are all in the first position, and the multi-valueness actually “binds” to the PARAM element, which also has a second position.
 
Example 5

<DELIVERY>
    <DELIVERY_ID>Czech Post</DELIVERY_ID>
    <DELIVERY_PRICE>69</DELIVERY_PRICE>
    <DELIVERY_PRICE_COD>89</DELIVERY_PRICE_COD>
</DELIVERY>
<DELIVERY>
    <DELIVERY_ID>Zásilkovna</DELIVERY_ID>
    <DELIVERY_PRICE>59</DELIVERY_PRICE>
    <DELIVERY_PRICE_COD>99</DELIVERY_PRICE_COD>
</DELIVERY>

A similar example to the previous one. The DELIVERY element is a multi-value element and the DELIVERY_ID, DELIVERY_PRICE and DELIVERY_PRICE_COD elements are simple elements.

:information_source:  You will encounter multi-value elements quite often. Typically these are elements containing URLs of images or alternative images, elements with parameters of products or elements for deliveries. Multi-value categories and variants are also common.

What is a multi-value element for?

It allows to combine multiple (tens or hundreds) related values into one element, so there is no need to create a special element with a different name for each value.

Example

<images>
    <image>url1</image>
    <image>url2</image>
    <image>url3</image>
    <image>url4</image>
    <image>url5</image>
</images>

Instead of

<images>
    <image1>url1</image1>
    <image2>url2</image2>
    <image3>url3</image3>
    <image4>url4</image4>
    <image5>url5</image5>
</images>

Working with multi-value elements

Correct writing of the path to the value of a multi-value element

To specify the path to the value of a multi-value element, we use conditions. And within those conditions, special attributes can sometimes be useful: @@POSITION or @@VALUE. But in a condition, we can use anything from MQL vocabulary or Element-Path vocabulary.

1. We want to target all values of a multi-value element

We will use the path to the multi-value element without conditions.

Example
Let’s have data:

<IMAGES>
    <IMAGE>url1</IMAGE>
    <IMAGE>url2</IMAGE>
    <IMAGE>url3</IMAGE>
    <IMAGE>url4</IMAGE>
    <IMAGE>url5</IMAGE>
</IMAGES>

The path to all values (url1, url2, url3, url4 and url5) of the image element looks like this: IMAGES | IMAGE.

2. We want to target specific values of a multi-value element

We will use conditions in the path.

Example
Let’s have the same data as the previous example:

<IMAGES>
    <IMAGE>url1</IMAGE>
    <IMAGE>url2</IMAGE>
    <IMAGE>url3</IMAGE>
    <IMAGE>url4</IMAGE>
    <IMAGE>url5</IMAGE>
</IMAGES>

The path to the url3 and url4 values of the image element looks like this IMAGES | IMAGE { @@POSITION IN (3;4) } or maybe like this IMAGES | IMAGE { @@VALUE IN ("url3"; "url4") }.

How do multi-value elements behave in rules?

We’ve devoted an entire post Multi-value elements in rules to this topic.

Displaying all values of a multi-value element

There are several ways to view all values of a multi-value element:

1. On the element values page

On the Elements page, click on a given multi-value element to open a page with all the values of that element.

2. In the table view

On the Products page click on “Table”, then “Custom” and the pencil icon and select our element. Then we click on the image icon, which will show us all the values.

Summary

  • What is a multi-value element?
    • A multi-value element is an element for which there is a value with position greater than one (even an empty value counts). That is, an element for which the condition { @@POSITION = 2 } can be written.
    • You will encounter multi-value elements very often indeed. Typically these are elements containing URLs of images, or alternative images, elements with parameters of products or elements for deliveries. Multi-value elements are also categories and variants .
       
  • What is multi-value element for?
    It allows you to unite several (dozens or hundreds) of related values into one element, and thus there is no need to create a special element with a different name for each value.
     
  • Working with multi-value elements
    • To specify the path to the value of a multi-value element, we use conditions. And within them special attributes can sometimes be useful: @@POSITION or @ @VALUE. In the condition, however, we can use anything from the MQL vocabulary or Element-Path.
    • You can see all the values of a multi-value element on the Elements page by clicking on the given element or on the Products page in the tabular view.