How to choose two elements in XSLT?

The bottom line is this: there is the XML file:
<items>
 <item id="1" src="/1.jpg">
 <item id="2" src="/2.jpg">
 <item id="3" src="/3.jpg">
 <item id="4" src="/4.jpg">
 <item id="5" src="/5.jpg">
</item></item></item></item></item></items>

For the slider images there is a pattern:
...
the <ul>
 <xsl:apply-templates select="items/item">
</xsl:apply-templates></ul>
...
<xsl:template match="item">
the <li>
 <img src="@src">
</li>
</xsl:template>


I need to li to add two items from the XML, so that the slider had two pictures in one unit. How to do it?
June 27th 19 at 15:21
2 answers
June 27th 19 at 15:23
Solution
So

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/items">
the <ul>
 <xsl:apply-templates select="item[position() mod 2 = 1]">
</xsl:apply-templates></ul>
</xsl:template>

 <xsl:template match="item">
the <li>
 <img src="{@src}">
 <img src="{following::item/@src}">
</li>
</xsl:template>
</xsl:stylesheet>


Will give
the <ul>
the <li>
 <img src="/1.jpg">
 <img src="/2.jpg">
</li>
the <li>
 <img src="/3.jpg">
 <img src="/4.jpg">
</li>
the <li>
 <img src="/5.jpg">
 <img src>
</li>
</ul>
Thank you, more concise version :) - Major_Tillman commented on June 27th 19 at 15:26
June 27th 19 at 15:25
Solution
<xsl:template match="item">
the <ul>
 <xsl:for-each select="item[position() mod 2 = 1]">
the <li>
 <xsl:apply-templates select=". | following-sibling::item[1]">
</xsl:apply-templates></li>
</xsl:for-each>
</ul>
</xsl:template>

<xsl:template match="item">
 <img src="{@url}">
</xsl:template>

Find more questions by tags XMLXSL & XSLT