Reputation: 181
I have some trouble with XSLT.
We have two nodes, like:
<main>
<part>
<block>1</block>
<block>2</block>
<block>3</block>
<block>4</block>
</part>
<article>
<block>A</block>
<block>B</block>
<block>B</block>
<block>D</block>
</article>
</main>
I need to view
<li>1</li>
<li>A</li>
<li>2</li>
<li>B</li>
<li>3</li>
<li>C</li>
<li>4</li>
<li>D</li>
At this moment wrote this, but it does not work as need:
<xsl:for-each select="part/*|article/*">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">
<li><xsl:value-of select="."/></li>
</xsl:when>
</xsl:choose>
</xsl:for-each>
Help me please.
Upvotes: 0
Views: 198
Reputation: 116992
Here's a very simple way to look at it:
XSLT 1.0
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<ul>
<xsl:for-each select="main/part/block">
<xsl:variable name="i" select="position()" />
<li><xsl:value-of select="."/></li>
<li><xsl:value-of select="../../article/block[$i]"/></li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Upvotes: 2