Answer the question
In order to leave comments, you need to log in
How to select two elements in XSLT?
The bottom line is this: there is an 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" />
</items>
...
<ul>
<xsl:apply-templates select="items/item" />
</ul>
...
<xsl:template match="item">
<li>
<img src="@src" />
</li>
</xsl:template>
Answer the question
In order to leave comments, you need to log in
Can it be like this
<?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">
<ul>
<xsl:apply-templates select="item[position() mod 2 = 1]" />
</ul>
</xsl:template>
<xsl:template match="item">
<li>
<img src="{@src}"/>
<img src="{following::item/@src}"/>
</li>
</xsl:template>
</xsl:stylesheet>
<ul>
<li>
<img src="/1.jpg"/>
<img src="/2.jpg"/>
</li>
<li>
<img src="/3.jpg"/>
<img src="/4.jpg"/>
</li>
<li>
<img src="/5.jpg"/>
<img src=""/>
</li>
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question