# Multi-value elements

**URL:** <https://forum.mergado.com/t/multi-value-elements/589>\
**Category:** Elements\
**Tags:** mergado-2, elements, multi-value\
**Created:** [September 27, 2022, 7:43am UTC](https://forum.mergado.com/t/multi-value-elements/589 "2022-09-27T07:43:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lehuy](https://forum.mergado.com/user_avatar/forum.mergado.com/lehuy/32/280_2.png) [@lehuy](https://forum.mergado.com/u/lehuy)\
**Post date:** [September 27, 2022, 7:43am UTC](https://forum.mergado.com/t/multi-value-elements/589/1 "2022-09-27T07:43:05Z")

</div>

In this post, we will learn:

- [What is a multi-value element?](https://forum.mergado.com/t/what-is-a-multi-value-element/589#what-is-a-multi-value-element-2)
- [What is the multi-value element for?](https://forum.mergado.com/t/multi-value-elements/589#what-is-a-multi-value-element-for-5)
- [Working with multi-value elements](https://forum.mergado.com/t/what-is-a-multi-value-element/589#working-with-multi-value-elements-6)
- [Summary](https://forum.mergado.com/t/what-is-a-multi-value-element/589#summary-14)

## Introduction

In [XML feeds](https://forum.mergado.com/t/elements/501#element-in-xml-feed-2), 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](https://forum.mergado.com/uploads/default/original/1X/d67a5466d7a3e001eee2191d4dee67716b4d97ae.png)

## What is a multi-value element?

A _multi-value element_ is an **element for which there is a value with [position](https://forum.mergado.com/t/position/766) greater than one** (even an empty value counts). That is, an element for which the condition `{ @@POSITION = 2 }` can be written.

 ![image](https://forum.mergado.com/uploads/default/original/1X/7e7c91d479c071bac1b24bde8fb9650c2e1e8034.png)

> ℹ &nbsp; 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_.

> ℹ &nbsp;For simple elements, the position of the value is always equal to 1 and does not need to be written in [path](https://forum.mergado.com/t/element-path/753#what-is-path-to-element-2).

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

### Examples

**Example 1**

```auto
<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 }`.  
&nbsp;  
**Example 2**

```auto
<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`.  
&nbsp;  
**Example 3**

```auto
<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).  
&nbsp;  
**Example 4**

```auto
<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.  
&nbsp;  
**Example 5**

```auto
<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.

> ℹ &nbsp;You will encounter multi-value elements quite often. Typically these are elements containing **URLs of images** or alternative images, elements with **[parameters](https://forum.mergado.cz/t/prace-s-parametry-v-mergadu-2/2249)** of products or elements for **[deliveries](https://forum.mergado.cz/t/prace-s-dopravou-v-mergadu-2/2264)**. 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**

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

```

Instead of

```auto
<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](https://forum.mergado.com/t/conditions-in-the-element-path/757).** And within those conditions, [special attributes](https://forum.mergado.com/t/special-attributes/749) can sometimes be useful: [@@POSITION](https://forum.mergado.com/t/position/766) or [@@VALUE](https://forum.mergado.com/t/value/751). But in a condition, we can use anything from [MQL vocabulary](https://forum.mergado.com/t/mql-language/755#mql-vocabulary-and-grammar-4) or [Element-Path vocabulary](https://forum.mergado.com/t/element-path/753#element-path-vocabulary-and-grammar-3).

#### 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:

```auto
<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:

```auto
<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](https://forum.mergado.com/t/multi-value-elements-in-rules/765) 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](https://forum.mergado.com/t/mergado-2-elements/586), 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](https://forum.mergado.com/t/mergado-2-the-products-page/587) click on “Table”, then “Custom” and the pencil icon and select our element. Then we click on the ![image](https://forum.mergado.com/uploads/default/original/1X/e0741b936040ee21c40dc58ca361552f7d3541e0.png) icon, which will show us all the values.

## Summary

- [What is a multi-value element?](https://forum.mergado.com/t/what-is-a-multi-value-element/589#what-is-a-multi-value-element-2)
  - A multi-value element is an **element for which there is a value with [position](https://forum.mergado.com/t/position/766) 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](https://forum.mergado.cz/t/prace-s-parametry-v-mergadu-2/2249)** of products or elements for **[deliveries](https://forum.mergado.cz/t/prace-s-dopravou-v-mergadu-2/2264)**. Multi-value elements are also **categories** and **variants**.  
&nbsp;

- [What is multi-value element for?](https://forum.mergado.com/t/multi-value-elements/589#what-is-a-multi-value-element-for-5)  
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.  
&nbsp;
- [Working with multi-value elements](https://forum.mergado.com/t/what-is-a-multi-value-element/589#working-with-multi-value-elements-6)
  - **To specify the path to the value of a multi-value element, we use [conditions](https://forum.mergado.com/t/conditions-in-the-element-path/757).** And within them [special attributes](https://forum.mergado.com/t/special-attributes/749) can sometimes be useful: [@@POSITION](https://forum.mergado.com/t/position/766) or [@ @VALUE](https://forum.mergado.com/t/value/751). In the condition, however, we can use anything from the [MQL vocabulary](https://forum.mergado.com/t/mql-language/755#mql-vocabulary-and-grammar-4) or [Element-Path](https://forum.mergado.com/t/element-path/753#element-path-vocabulary-and-grammar-3).
  - 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.
