Can anyone help? I am very new to XSLT, and am trying to build a table of elements; I've simplified my example down below, and have managed to get output onto rows of three cells, but I'm getting unwanted whitespace between the rows - could anyone tell me what I'm doing wrong here?
Also do I need two <apply-templates />
in my Rows Match?
Many thanks in advance, Alex
This is XML:
<?xml version="1.0" encoding="iso-8859-1"?>
<products>
<r t='title1'>...</r>
<r t='title2'>...</r>
<r t='title3'>...</r>
<r t='title4'>...</r>
<r t='title5'>...</r>
<r t='title6'>...</r>
<r t='title7'>...</r>
<r t='title8'>...</r>
<r t='title9'>...</r>
</products>
This is XSL:
<!-- Rows -->
<xsl:template match="r[position() mod 3 = 1]">
<div class="row">
<xsl:apply-templates mode="cell" select="." />
<xsl:apply-templates mode="cell" select="./following-sibling::r[not(position() > 2)]" />
</div>
</xsl:template>
<!-- Cells -->
<xsl:template match="r" mode="cell">
<div class="cell">
<xsl:value-of select="@t"/>
</div>
</xsl:template>
MY OUTPUT (Note the unwanted whitespace between rows):
<div class="row">
<div class="cell">Title1</div>
<div class="cell">Title2</div>
<div class="cell">Title3</div>
</div>
<div class="row">
<div class="cell">Title4</div>
<div class="cell">Title5</div>
<div class="cell">Title6</div>
</div>
<div class="row">
<div class="cell">Title7</div>
<div class="cell">Title8</div>
<div class="cell">Title9</div>
</div>