We help IT Professionals succeed at work.

2 column XSL in "snake" format

2,137 Views
Last Modified: 2013-11-18
I need help creating XSL to display one field in two columns that snake. For example, if there are 29 rows of data, I want items 1-15 to show up in column 1 and items 16 - 29 in column 2. Below is a page generated by WSS2007 in Sharepoint Designer that alternates the items between the two columns, which is not what I need. I do not know XSL enough to make the necessary modifications.

<%@ Page Language="C#" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="WebPartPages" namespace="Microsoft.SharePoint.WebPartPages" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html dir="ltr">

<head runat="server">
<META name="WebPartPageExpansion" content="full">
<meta name="ProgId" content="SharePoint.WebPartPage.Document" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<meta name="Microsoft Theme" content="Belltown 1011, default">
<style type="text/css">
@import url('ows.css');
</style>
</head>

<body>

<form id="form1" runat="server">
      <WebPartPages:DataFormWebPart runat="server" IsIncluded="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="0" Title="" ListName="{F7D98E26-DEE1-42DA-8384-31B59425E5CA}" Default="FALSE" DisplayName="" __markuptype="vsattributemarkup" __WebPartId="{F2E19FA8-0507-4293-BEDA-B173E1116B44}" id="g_f2e19fa8_0507_4293_beda_b173e1116b44" __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
      <DataSources>
            <SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="&lt;View&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;Title&quot; Ascending=&quot;TRUE&quot;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;/View&gt;" id="spdatasource2"><SelectParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="F7D98E26-DEE1-42DA-8384-31B59425E5CA"/></SelectParameters><DeleteParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="F7D98E26-DEE1-42DA-8384-31B59425E5CA"/></DeleteParameters><UpdateParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="F7D98E26-DEE1-42DA-8384-31B59425E5CA"/></UpdateParameters><InsertParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="F7D98E26-DEE1-42DA-8384-31B59425E5CA"/></InsertParameters></SharePoint:SPDataSource>
      </DataSources>
      <ParameterBindings>
            <ParameterBinding Name="ListID" Location="None" DefaultValue="F7D98E26-DEE1-42DA-8384-31B59425E5CA"/>
            <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
            <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
            <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
      </ParameterBindings>
      <datafields>@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@Title,Title;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;@URL,URL;@Comments,Notes;</datafields>
      <XSL>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
      <xsl:output method="html" indent="no"/>
      <xsl:decimal-format NaN=""/>
      <xsl:param name="dvt_apos">&apos;</xsl:param>
      <xsl:variable name="dvt_1_automode">0</xsl:variable>
      
      <xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
            <xsl:call-template name="dvt_1"/>
      </xsl:template>
      
      <xsl:template name="dvt_1">
            <xsl:variable name="dvt_StyleName">2ColCma</xsl:variable>
            <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
            <table border="0" width="100%">
                  <tr>
                        <xsl:call-template name="dvt_1.body">
                              <xsl:with-param name="Rows" select="$Rows" />
                        </xsl:call-template>
                  </tr>
            </table>
      </xsl:template>
      <xsl:template name="dvt_1.body">
            <xsl:param name="Rows" />
            <xsl:for-each select="$Rows">
                  <xsl:call-template name="dvt_1.rowview" />
            </xsl:for-each>
      </xsl:template>
      <xsl:template name="dvt_1.rowview">
            <td valign="top" width="50%" class="ms-GRFont" >
                  <b>
                        <a href="{substring-before(@URL, ', ')}">
                              <xsl:value-of select="substring-after(@URL, ', ')" />
                        </a>
                  </b>
                  <br />
                  <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
                        <br /><span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view" />
                  </xsl:if>
            </td>
            <xsl:if test="position() mod 2 = 0" ddwrt:cf_ignore="1">
                  <xsl:text disable-output-escaping="yes">&lt;/tr&gt;</xsl:text>
                  <xsl:if test="position() != last()" ddwrt:cf_ignore="1">
                        <xsl:text disable-output-escaping="yes">&lt;tr&gt;</xsl:text>
                  </xsl:if>
            </xsl:if>
      </xsl:template>
</xsl:stylesheet>      </XSL>
</WebPartPages:DataFormWebPart>
</form>

</body>

</html>
Comment
Watch Question

Information Architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
That did it!The rest of the stuff is required for Sharepoint. I just pasted in your code - replacing the xsl:stylesheet area and it works as I need. Please reply to post https://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/MS-SharePoint/Q_22738577.html as it is the same question ask differently and I will assign those points to you as well. I have struggled with this for some time.
Gertone (Geert Bormans)Information Architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
no need to award double points
refer to the answer here and ask for a PAQ-points refund

cheers

Geert
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.