Pre
I have this XML
<root>
<subscribers nullDays="5">
<subscriber>
<ThumbURL>
http://cs323321.userapi.com/v323321550/eea/iakdB20fx20.jpg
</ThumbURL>
</subscriber>
<subscriber>
<ThumbURL>
http://cs323321.userapi.com/v323321550/f24/CQ-Zm0_BWnQ.jpg
</ThumbURL>
</subscriber>
...
<subscriber>
<ThumbURL>...</ThumbURL>
</subscriber>
</subscribers>
</root>
After XSLT I get HTML where subscriber will be separated into each div with img tag inside.
Question
How I can generate div equals nullDays attribute using xsl:for-each? Following code requires subscriber nodes more than nullDays, but it cannot be exist:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"xml:base="http://www.w3.org/1999/xhtml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" indent="yes"/>
<xsl:template match="root">
<xsl:element name="html">
<xsl:element name="head"/>
<xsl:element name="body">
<xsl:variable name="nullDays" select="subscribers/@nullDays"/>
<xsl:for-each select="subscribers/subscriber">
<xsl:if test="(position() mod $nullDays) = 0">
<xsl:element name="div">
<xsl:attribute name="class">empty-div</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Thank you!
<subscribers>
at the point the above code takes effect. (Also, the desired output does usually help a lot.) – Thomas W<subscriber>
less thansubscribers/@nullDays
this for-each doesn't prints<div class="empty-div"></div>
subscribers/@nullDays
+1 times – denisldaur