XSLT - create multiple (n) html tables of the same size (in this case 3x3)

Help Question 1

Help Question 2

Well, both of the previous links are about discussing how to create cells and rows in tables. I was hoping to find an extended example that showed how to create several tables from N-cells each (in this case, 9 cells each - 3x3). I tried for some time to use the logic of two examples and about 500 other places on the Internet, but could not crack the nut. Could someone possibly contribute to the above links, shed some light on how it would be possible to build N-tables from 3x3 from one data set as opposed to one table of certain rows?

One of the most difficult limitations that I find is that each table must be the same size, empty rows / cells must be filled to fit 3x3 size. It would be great if the published solution not only allowed it for 3x3, but also explained the theory in such a way that a person could get away from understanding how to extrapolate it to build tables of different sizes.

If that helps, the dataset I'm working with is the result of the SharePoint XML for the Data View web part. The returned structure is / dsQueryResult / Rows / Row / @values. I group the “recognized” flag and the reverse date order in the request itself, so the data is ordered as it should be. The first element is cut out for a special display, and the rest are cut into these several tables of equal size, which will be displayed as grouped displays for the javascript rotator.

Thanks in advance!

EDIT:

After seeing Alejandro's answer, I went to build it in my environment (SharePoint Designer, unfortunately) and got the following result. I changed the pSequence parameter to "/ dsQueryResponse / Rows / *" and building the table handled the fun. However, when I printed out the identifier and title of each object, I got the following:

<TABLE>
  <TR>
    <TD>35 - Concern for Community</TD>
    <TD>35 - Concern for Community</TD>
    <TD>35 - Concern for Community</TD>
  </TR>
  <TR>
    <TD>35 - Concern for Community</TD>
    <TD>35 - Concern for Community</TD>
    <TD>35 - Concern for Community</TD>
  </TR>
  <TR>
    <TD>35 - Concern for Community</TD>
    <TD>35 - Concern for Community</TD>
    <TD>35 - Concern for Community</TD>
  </TR>
</TABLE>
<TABLE>
  <TR>
    <TD>26 - Tequila Sunset</TD>
    <TD>26 - Tequila Sunset</TD>
    <TD>26 - Tequila Sunset</TD>
  </TR>
  <TR>
    <TD>26 - Tequila Sunset</TD>
    <TD>26 - Tequila Sunset</TD>
    <TD>26 - Tequila Sunset</TD>
  </TR>
  <TR>
    <TD>26 - Tequila Sunset</TD>
    <TD>26 - Tequila Sunset</TD>
    <TD>26 - Tequila Sunset</TD>
  </TR>
</TABLE>
<TABLE>
  <TR>
    <TD>17 - Oil Well Flare</TD>
    <TD>17 - Oil Well Flare</TD>
    <TD>17 - Oil Well Flare</TD>
  </TR>
  <TR>
    <TD>17 - Oil Well Flare</TD>
    <TD>17 - Oil Well Flare</TD>
    <TD>17 - Oil Well Flare</TD>
  </TR>
  <TR>
    <TD>17 - Oil Well Flare</TD>
    <TD>17 - Oil Well Flare</TD>
    <TD>17 - Oil Well Flare</TD>
  </TR>
</TABLE>

- 1-10 , 3 .

2:

, . XML :

<xml>
  <dsQueryResponse>
    <x:schema></x:schema>
    <Rows>
      <Row Title="Title 1" ID="33" .... />
      <Row Title="Title 2" ID="32" .... />
      <Row Title="Title 3" ID="31" .... />
      <Row Title="Title 4" ID="30" .... />
      <Row Title="Title 5" ID="29" .... />
      <Row Title="Title 6" ID="28" .... />
      <Row Title="Title 7" ID="27" .... />
      <Row Title="Title 8" ID="24" .... />
      <Row Title="Title 9" ID="20" .... />
      <Row Title="Title 10" ID="19" .... />
      <Row Title="Title 11" ID="17" .... />
      ...
    </Rows>
  </dsQueryResponse>
</xml>

, , , , , , , . "" node.

( ):

<ul id="photoTabs" class="tabs">
  <li>Featured Photo</li>
  <li>Archived Photos (26) [COUNT OF ITEMS MINUS 1])</li>
</ul>
<div id="photoPanes" class="panes">
  <div>
    <p class="photoLibraryImageWrapper">
      <strong>[TITLE OF FIRST ITEM]</strong></p>
      <div style="text-align: center">
        <img style="border-bottom: 0px solid; border-left: 0px solid; border-top: 0px solid; border-right: 0px solid" alt="TITLE OF FIRST ITEM" src="SOURCE OF PHOTO"><br>
        <span class="photoLibraryItemCopyright">[PHOTO CREDIT]</span><br>
        <span class="photoLibraryItemCopyright">[PHOTO COURTESY OF]</span>
      </div>
      <div class="photoLibraryImageWrapper">
        <p>[PHOTO DESCRIPTION]</p>
      </div>
      <div>
        <div style="float: left">
          <a class="prev browse left"></a>
        </div>
        <div class="scrollable">
          <div class="items">
           <div>
            <table>
              <tr>
                <td>
                  Title 2
                </td>
                <td>
                  Title 3
                </td>
                <td>
                  Title 4
                </td>
              </tr>
              <tr>
                <td>
                  Title 5
                </td>
                <td>
                  Title 6
                </td>
                <td>
                  Title 7
                </td>
              </tr>
              <tr>
                <td>
                  Title 8
                </td>
                <td>
                  Title 9
                </td>
                <td>
                  Title 10
                </td>
              </tr>
        </table>
       </div>
       <div>
        <table>
            <tr>
              <td>
                Title 11
              </td>
              <td>
                Title 12
              </td>
              <td>
                Title 13
              </td>
            </tr>
            <tr>
              <td>
                Title 14
              </td>
              <td>
                Title 15
              </td>
              <td>
                Title 16
              </td>
            </tr>
            <tr>
              <td>
                Title 17
              </td>
              <td>
                Title 18
              </td>
              <td>
                Title 19
              </td>
            </tr>
        </table>
       </div>
       <div>
         <table>
            <tr>
              <td>
                Title 20
              </td>
              <td>
                Title 21
              </td>
              <td>
                &nbsp;
              </td>
            </tr>
            <tr>
              <td>
                &nbsp;
              </td>
              <td>
                &nbsp;
              </td>
              <td>
                &nbsp;
              </td>
            </tr>
            <tr>
              <td>
                &nbsp;
              </td>
              <td>
                &nbsp;
              </td>
              <td>
                &nbsp;
              </td>
            </tr>
        </table>
      </div>
      </div>
      <div style="float: left">
        <a class="next browse right"></a>
      </div>
    </div>
   </div>

, , , Alejandro (ninja-esque), , , . , 9 , 9 . $pSequence/ /dsQueryResponse/Rows/ * ( ), .

, , - , +1 , , .:)

+1
1

:

:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="pRows" select="3"/>
    <xsl:param name="pColumns" select="3"/>
    <xsl:template match="/" name="tables">
        <xsl:param name="pSequence" select="*/*"/>
        <xsl:variable name="vSize" select="$pRows * $pColumns"/>
        <xsl:for-each select="$pSequence[position() mod $vSize = 1]">
            <xsl:variable name="vPosition" select="position()"/>
            <table>
                <xsl:call-template name="rows">
                    <xsl:with-param name="pSequence"
                         select="$pSequence[
                                    position() > ($vPosition - 1) * $vSize
                                     and
                                    $vPosition * $vSize + 1 > position()
                                 ]"/>
                </xsl:call-template>
            </table>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="rows">
        <xsl:param name="pSequence" select="/.."/>
        <xsl:param name="pRow" select="$pRows"/>
        <xsl:if test="$pRow">
            <xsl:call-template name="rows">
                <xsl:with-param name="pSequence" select="$pSequence"/>
                <xsl:with-param name="pRow" select="$pRow - 1"/>
            </xsl:call-template>
            <tr>
                <xsl:call-template name="columns">
                    <xsl:with-param name="pSequence"
                         select="$pSequence[
                                    position() > ($pRow - 1) * $pColumns
                                     and
                                    $pRow * $pColumns + 1 > position()
                                 ]"/>
                </xsl:call-template>
            </tr>
        </xsl:if>
    </xsl:template>
    <xsl:template name="columns">
        <xsl:param name="pSequence" select="/.."/>
        <xsl:param name="pColumn" select="$pColumns"/>
        <xsl:if test="$pColumn">
            <xsl:call-template name="columns">
                <xsl:with-param name="pSequence" select="$pSequence"/>
                <xsl:with-param name="pColumn" select="$pColumn - 1"/>
            </xsl:call-template>
            <td>
                <xsl:apply-templates select="$pSequence[$pColumn]"/>
            </td>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

Input:

<root>
    <item>1</item>
    <item>2</item>
    <item>3</item>
    <item>4</item>
    <item>5</item>
    <item>6</item>
    <item>7</item>
    <item>8</item>
    <item>9</item>
    <item>10</item>
    <item>11</item>
    <item>12</item>
    <item>13</item>
    <item>14</item>
    <item>15</item>
    <item>16</item>
</root>

:

<table>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
    </tr>
    <tr>
        <td>4</td>
        <td>5</td>
        <td>6</td>
    </tr>
    <tr>
        <td>7</td>
        <td>8</td>
        <td>9</td>
    </tr>
</table>
<table>
    <tr>
        <td>10</td>
        <td>11</td>
        <td>12</td>
    </tr>
    <tr>
        <td>13</td>
        <td>14</td>
        <td>15</td>
    </tr>
    <tr>
        <td>16</td>
        <td></td>
        <td></td>
    </tr>
</table>

. , ... , - . .

EDIT: , ( , )

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="table.xsl"/>
    <xsl:output method="html"/>
    <xsl:template match="/">
        <xsl:call-template name="tables">
            <xsl:with-param name="pSequence"
                 select="xml/dsQueryResponse/Rows/Row[position()!=1]"/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template match="Row">
        <xsl:value-of select="@Title"/>
    </xsl:template>
</xsl:stylesheet>

:

<xml>
    <dsQueryResponse>
        <x:schema xmlns:x="x"></x:schema>
        <Rows>
            <Row Title="Title 1" ID="33"/>
            <Row Title="Title 2" ID="32"/>
            <Row Title="Title 3" ID="31"/>
            <Row Title="Title 4" ID="30"/>
            <Row Title="Title 5" ID="29"/>
            <Row Title="Title 6" ID="28"/>
            <Row Title="Title 7" ID="27"/>
            <Row Title="Title 8" ID="24"/>
            <Row Title="Title 9" ID="20"/>
            <Row Title="Title 10" ID="19"/>
            <Row Title="Title 11" ID="17"/>
            <Row Title="Title 12" ID="132"/>
            <Row Title="Title 13" ID="131"/>
            <Row Title="Title 14" ID="130"/>
            <Row Title="Title 15" ID="129"/>
            <Row Title="Title 16" ID="128"/>
            <Row Title="Title 17" ID="127"/>
            <Row Title="Title 18" ID="124"/>
            <Row Title="Title 19" ID="120"/>
            <Row Title="Title 20" ID="119"/>
            <Row Title="Title 21" ID="117"/>
        </Rows>
    </dsQueryResponse>
</xml>

:

<table>
   <tr>
      <td>Title 2</td>
      <td>Title 3</td>
      <td>Title 4</td>
   </tr>
   <tr>
      <td>Title 5</td>
      <td>Title 6</td>
      <td>Title 7</td>
   </tr>
   <tr>
      <td>Title 8</td>
      <td>Title 9</td>
      <td>Title 10</td>
   </tr>
</table>
<table>
   <tr>
      <td>Title 11</td>
      <td>Title 12</td>
      <td>Title 13</td>
   </tr>
   <tr>
      <td>Title 14</td>
      <td>Title 15</td>
      <td>Title 16</td>
   </tr>
   <tr>
      <td>Title 17</td>
      <td>Title 18</td>
      <td>Title 19</td>
   </tr>
</table>
<table>
   <tr>
      <td>Title 20</td>
      <td>Title 21</td>
      <td></td>
   </tr>
   <tr>
      <td></td>
      <td></td>
      <td></td>
   </tr>
   <tr>
      <td></td>
      <td></td>
      <td></td>
   </tr>
</table>

. xsl:apply-templates , xsl:value-of.

+2

All Articles