K
K
Konstantin2015-11-06 08:08:48
XSL & XSLT
Konstantin, 2015-11-06 08:08:48

How to organize pairwise output of list items in UMI.CMS?

Good afternoon!
It is required to implement the output of a list of elements in pairs, for example:

<div>
<span class="element-1">Элемент 1</span>
<span class="element-2">Элемент 2</span>
</div>
<div>
<span class="element-3">Элемент 3</span>
<span class="element-4">Элемент 4</span>
</div>

Those. 2 elements are in the div container.
I tried to use the following scheme - add tags depending on
the position of the element:
<xsl:template match="item" mode="portfolio_item">
<xsl:if test="position() mod 2 = 1">
  <div>
</xsl:if>
<span class="element-{position()}" >
<xsl:value-of select='document(concat("upage://", @id,
".preview"))/udata/property/value' disable-output-escaping="yes" />
</span>
<xsl:if test="position() mod 2 = 0 or position() = last()">
  </div>
</xsl:if>
</xsl:template>

Those. add a tag before an odd element and after an odd element
or the last one in the list - a closing tag.
But in the end, every time I got an error, although the construction logic is correct.
Can you please tell me how to display the elements of a list in pairs? Is it possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
i, 2015-11-06
@ilyarsoftware

Try like this:

<xsl:param name="colnum" select="2"/>

<xsl:template match="udata[@module = 'catalog'][@method = 'getObjectsList']">
  <xsl:apply-templates select="lines/item[position() = 1]|lines/item[position() mod $colnum = 1]"/>
</xsl:template>

<xsl:template match="item">
  <div>
     <xsl:apply-templates select=".|following-sibling::item[position() &lt; $colnum]" mode="div"/>
  </div>
</xsl:template>

<xsl:template match="item" mode="div">
  <span class="element-{@id}" >
    <xsl:value-of select="."/>
  </span>
</xsl:template>

Example demonstration .
There is an article on this topic: Multi-column tables in XSLT templates and a similar issue is covered in the topic: Displaying catalog objects .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question