user1491600
user1491600

Reputation: 114

Wrap a div around every three divs using xslt

The following code is able to select the first element in each row and display it, but how do I wrap the rowContainer class around the first element and its next two children (if it has any).

 <xsl:for-each select="ViewAll/ROW[position() mod 3 = 1]">
                <div class="rowContainer" align="center">
                **<xsl:for-each select="the current position and the next two">**
                    <div class="grid" align="center">
                        <table class="appTable" border="0" width="auto" bgcolor="">
                            <tr>
                            <td rowspan='2' width="80px" height="80px">
                                <img src="{substring(SC_DF_FIELD_3,9,string-length(substring-before(SC_DF_FIELD_3,'&gt;'))-21)}"/>
                            </td>
                            <td width="auto" height="60px"><b class="appName"><xsl:value-of select="SC_DF_FIELD_1"/></b><div style="display:none">;</div></td>
                            </tr>
                            <tr style="vertical-align:text-top">
                            <td>                            
                                <div class="type"><xsl:value-of select="SC_DF_FIELD_5"/><div style="display:none">;</div></div>
                                <div class="price"><xsl:value-of select="SC_DF_FIELD_7"/><div style="display:none">;</div></div>
                                <div class="url" style="display:none"><xsl:value-of select="SC_DF_FIELD_6"/><div style="display:none">;</div></div>
                                <div class="date" style="display:none"><xsl:value-of select="SC_SYS_DF_DT_UPDATED"/><div style="display:none">;</div></div>
                            </td>
                            </tr>
                            <tr>
                            <td colspan="2" align='left' height="60px"> 
                                <div class="description"><b>Description: </b><xsl:value-of select="SC_DF_FIELD_2"/></div>
                            </td>
                            </tr>
                            <tr>
                            <td colspan='2' style="vertical-align:text-top" align='center'>     
                                <div class="downLoadButton"><ul><li class="view"><a onclick='javascript:SerialPopUp($(this).parents("*:eq(5)").text())' style="color:019DDD"><b>Download</b><div style="display:none">;</div></a></li></ul></div>
                            </td>
                            </tr>
                        </table>
                    </div>
                  **</xsl:for-each>**
                </div>
            </xsl:for-each>

In the end I would like the resulting code to appear as follows:

<div class="rowContainer">
      <div class="grid"/>
      <div class="grid"/>
      <div class="grid"/>
</div>

<div class="rowContainer">
      <div class="grid"/>
      <div class="grid"/>
      <div class="grid"/>
</div>

<div class="rowContainer">
      <div class="grid"/>
      <div class="grid"/>
</div>

Thank you in advance for any help you are able to give me.

Upvotes: 1

Views: 298

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167581

You have not shown the structure of the input XML but

<xsl:for-each select=". | following-sibling::ROW[position() &lt; 3]">

should probably do.

Upvotes: 1

Related Questions