Solved

SharePoint Dataview XSL Help

Posted on 2013-01-16
2
1,008 Views
Last Modified: 2013-01-20
Hi experts!

Currently my dataview is only using 1 item (image of left, text on right)

How do I change it to show 4 items horizontally (image on top, text bottom)

This is my XSL code

<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">RepForm3</xsl:variable>
		<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
		<xsl:variable name="RowLimit" select="1" />
		<table border="0" width="100%">
			<xsl:call-template name="dvt_1.body">
				<xsl:with-param name="Rows" select="$Rows" />
				<xsl:with-param name="FirstRow" select="1" />
				<xsl:with-param name="LastRow" select="$RowLimit" />
			</xsl:call-template>
		</table>
	</xsl:template>
	<xsl:template name="dvt_1.body">
		<xsl:param name="Rows" />
		<xsl:param name="FirstRow" />
		<xsl:param name="LastRow" />
		<xsl:for-each select="$Rows">
			<xsl:variable name="dvt_KeepItemsTogether" select="false()" />
			<xsl:variable name="dvt_HideGroupDetail" select="false()" />
			<xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow) or $dvt_KeepItemsTogether">
				<xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">
					<xsl:call-template name="dvt_1.rowview" />
				</xsl:if>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="dvt_1.rowview">
		<tr>
			<td>
				<table border="0" cellspacing="0" width="100%">
					<tr>
						<td width="25%" class="ms-vb" rowspan="2">
					<img border="0" src="{@Thumbnail}" />
						</td>
						<td width="75%" class="ms-vb" height="5%">
						<a href="{substring-before(@Page_x002f_URL_x0020_to_x0020_li, ', ')}">
								<xsl:value-of select="substring-after(@Page_x002f_URL_x0020_to_x0020_li, ', ')" />
							</a></td>
					</tr>
					<tr>
						<td width="75%" class="ms-vb"><xsl:value-of select="@Highlights_x0020_Description" disable-output-escaping="yes" /></td>
						
					</tr>
					<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
						<tr>
							<td colspan="99" class="ms-vb">
								<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view" />
							</td>
						</tr>
					</xsl:if>
				</table>
			</td>
		</tr></xsl:template>
</xsl:stylesheet>	

Open in new window


I'm using SP2007
0
Comment
Question by:sharepoint2013
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 38787908
Hi,
sorry to have just a link, but with that information you should be able to create the requested format:
http://stackoverflow.com/questions/9407507/how-to-get-a-xsl-to-display-results-in-multi-columns

HTH
Rainer
0
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 500 total points
ID: 38797911
Hello,

see this question: http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/MS-SharePoint/Q_27877111.html

Explanation:
Add table row tags around the for-each loop that calls the rows, and after each 4th row add a closing and an opening tr tag. The latter must be done in escaped notation, otherwise, the thing will bomb.

XSL applied to your DVWP above (just the dvt_.body and dvt_1.rowview templates):

	<xsl:template name="dvt_1.body">
		<xsl:param name="Rows"/>
		<!-- start the first row of the table outside of the row loop -->
		<tr>
			<xsl:for-each select="$Rows">
				<xsl:call-template name="dvt_1.rowview" />
			</xsl:for-each>
		<!-- end the last row of the table -->
		</tr>
	</xsl:template>
	
	<xsl:template name="dvt_1.rowview">
			<td>
				<table border="0" cellspacing="0" width="100%">
					<tr>
						<td width="25%" class="ms-vb" rowspan="2">
					<img border="0" src="{@Thumbnail}" />
						</td>
						<td width="75%" class="ms-vb" height="5%">
						<a href="{substring-before(@Page_x002f_URL_x0020_to_x0020_li, ', ')}">
								<xsl:value-of select="substring-after(@Page_x002f_URL_x0020_to_x0020_li, ', ')" />
							</a></td>
					</tr>
					<tr>
						<td width="75%" class="ms-vb"><xsl:value-of select="@Highlights_x0020_Description" disable-output-escaping="yes" /></td>
						
					</tr>
					<xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
						<tr>
							<td colspan="99" class="ms-vb">
								<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view" />
							</td>
						</tr>
					</xsl:if>
				</table>
			</td>
			<!-- after each 4th item, insert a closing tr tag and an opening tr tag for the next row -->
			<xsl:if test="position() mod 4 = 0">
				<xsl:text disable-output-escaping="yes">&lt;/tr&gt;</xsl:text>
				<xsl:text disable-output-escaping="yes">&lt;tr&gt;</xsl:text>
			</xsl:if>
	</xsl:template>

Open in new window


cheers, teylyn
0

Featured Post

Office 365 Training for Admins

Learn how to provision tenants, synchronize on-premise Active Directory, and implement Single Sign-On with these master level course.  Only from Platform Scholar

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question