Solved

SharePoint Dataview XSL Help

Posted on 2013-01-16
2
963 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
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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now