EmbeddedFilePreview

Nov 25, 2010 at 1:30 AM
Edited Nov 25, 2010 at 5:13 AM

 

Usage:
<xsl:call-template name="EmbeddedFilePreview">
	<xsl:with-param name="FileType" select="@File_x0020_Type"/>
	<xsl:with-param name="FilePath" select="@FileRef"/>
	<xsl:with-param name="paramHeight" select="500"/>
	<xsl:with-param name="paramWidth" select="1000"/>
	<xsl:with-param name="curr_Site" select="$curr_Site" />
</xsl:call-template>
curr_Site is only required for displaying .vsd files.  I pull the value in using the Server Variable: SERVER_NAME
paramHeight and paramWidth are optional.

EmbeddedFilePreview Template:
<xsl:template name="EmbeddedFilePreview">
	<xsl:param name="FileType" />
	<xsl:param name="FilePath" />
	<xsl:param name="paramHeight" />
	<xsl:param name="paramWidth" />
	<xsl:param name="curr_Site" />

	<xsl:variable name="Height">
		<xsl:choose>
			<xsl:when test="string-length($paramHeight) &gt; 0">
				<xsl:value-of select="$paramHeight"/>
			</xsl:when>
			<xsl:otherwise>
				500
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="Width">
		<xsl:choose>
			<xsl:when test="string-length($paramWidth) &gt; 0">
				<xsl:value-of select="$paramWidth"/>
			</xsl:when>
			<xsl:otherwise>
				100%
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:choose>
		<xsl:when test="$FileType = 'pdf'"> 
			<object>
				<xsl:attribute name="data">				
					<xsl:value-of select="$FilePath" />
				</xsl:attribute>
				<xsl:attribute name="type">
					<xsl:text>application/pdf</xsl:text>
				</xsl:attribute>
				<xsl:attribute name="width">
					<xsl:value-of select="$Width" />
				</xsl:attribute> 
				<xsl:attribute name="height">
					<xsl:value-of select="$Height" />
				</xsl:attribute>
				<p>It appears you don't have a PDF plugin for this browser.</p>
			</object>
		</xsl:when>
		<xsl:when test="$FileType = 'jpg'">
			<object>
				<xsl:attribute name="data">				
					<xsl:value-of select="$FilePath" />
				</xsl:attribute>
				<xsl:attribute name="type">				
					<xsl:text>image/jpeg</xsl:text>
				</xsl:attribute>				
				<xsl:attribute name="width">
					<xsl:value-of select="$Width" />
				</xsl:attribute> 
				<xsl:attribute name="height">
					<xsl:value-of select="$Height" />
				</xsl:attribute> 
			</object>
		</xsl:when>
		<xsl:when test="$FileType = 'gif'">
			<object>
				<xsl:attribute name="data">				
					<xsl:value-of select="$FilePath" />
				</xsl:attribute>
				<xsl:attribute name="type">				
					<xsl:text>image/gif</xsl:text>
				</xsl:attribute>
				<xsl:attribute name="width">
					<xsl:value-of select="$Width" />
				</xsl:attribute> 
				<xsl:attribute name="height">
					<xsl:value-of select="$Height" />
				</xsl:attribute> 
			</object>
		</xsl:when>
		<xsl:when test="$FileType = 'png'">
			<object>
				<xsl:attribute name="data">				
					<xsl:value-of select="$FilePath" />
				</xsl:attribute>
				<xsl:attribute name="type">				
					<xsl:text>image/png</xsl:text>
				</xsl:attribute>
				<xsl:attribute name="width">
					<xsl:value-of select="$Width" />
				</xsl:attribute> 
				<xsl:attribute name="height">
					<xsl:value-of select="$Height" />
				</xsl:attribute> 
			</object>
		</xsl:when>
		<xsl:when test="$FileType = 'mp3'">
			<embed>
				<xsl:attribute name="src">
					<xsl:value-of select="$FilePath" />
				</xsl:attribute>
				<xsl:attribute name="autostart">
					<xsl:text>true</xsl:text>
				</xsl:attribute>
				<xsl:attribute name="hidden">
					<xsl:text>false</xsl:text>
				</xsl:attribute>
				<xsl:attribute name="width">
					<xsl:value-of select="$Width" />
				</xsl:attribute> 
				<xsl:attribute name="height">
					<xsl:value-of select="$Height" />
				</xsl:attribute> 
			</embed>
		</xsl:when>
		<xsl:when test="$FileType = 'vsd'">
			<xsl:choose>
				<xsl:when test="$curr_Site = ''">
					<b>The current site parameter *must* be provided!</b>
				</xsl:when>
				<xsl:otherwise>
					<object>
						<xsl:attribute name="classid">				
							<xsl:text>CLSID:279D6C9A-652E-4833-BEFC-312CA8887857</xsl:text>
						</xsl:attribute>
						<xsl:attribute name="id">				
							<xsl:text>VSDViewer</xsl:text>
						</xsl:attribute>
						<xsl:attribute name="width">
							<xsl:value-of select="$Width" />
						</xsl:attribute> 
						<xsl:attribute name="height">
							<xsl:value-of select="$Height" />
						</xsl:attribute>
						<xsl:text disable-output-escaping="yes">
						&lt;param name=&quot;BackColor&quot; value=&quot;16777120&quot;&gt;
						&lt;param name=&quot;AlertsEnabled&quot; value=&quot;1&quot;&gt;
						&lt;param name=&quot;ContextMenuEnabled&quot; value=&quot;1&quot;&gt;
						&lt;param name=&quot;GridVisible&quot; value=&quot;0&quot;&gt;
						&lt;param name=&quot;HighQualityRender&quot; value=&quot;1&quot;&gt;
						&lt;param name=&quot;PageColor&quot; value=&quot;16777215&quot;&gt;
						&lt;param name=&quot;PageVisible&quot; value=&quot;1&quot;&gt;
						&lt;param name=&quot;PropertyDialogEnabled&quot; value=&quot;1&quot;&gt;
						&lt;param name=&quot;ScrollbarsVisible&quot; value=&quot;1&quot;&gt;
						&lt;param name=&quot;ToolbarVisible&quot; value=&quot;1&quot;&gt;
						&lt;param name=&quot;SRC&quot; value=&quot;http://</xsl:text>
						<xsl:value-of select="concat($curr_Site, $FilePath)"/><xsl:text disable-output-escaping="yes">&quot;&gt;
						&lt;param name=&quot;CurrentPageIndex&quot; value=&quot;0&quot;&gt;
						&lt;param name=&quot;Zoom&quot; value=&quot;-1&quot;&gt;</xsl:text>
						<p>It appears you don't have a Visio Viewer plugin for this browser.</p>
					</object>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>
		<xsl:when test="$FileType = 'wmv'">
			<object>
				<xsl:attribute name="type">				
					<xsl:text>video/x-ms-wmv</xsl:text>
				</xsl:attribute>
				<xsl:attribute name="data">		
					<xsl:value-of select="$FilePath" />
				</xsl:attribute>
				<xsl:attribute name="width">
					<xsl:value-of select="$Width" />
				</xsl:attribute> 
				<xsl:attribute name="height">
					<xsl:value-of select="$Height" />
				</xsl:attribute> 
				<xsl:text disable-output-escaping="yes">
				&lt;param name=&quot;src&quot; value=&quot;</xsl:text>
				<xsl:value-of select="$FilePath"/><xsl:text disable-output-escaping="yes">&quot;&gt;
				&lt;param name=&quot;autostart&quot; value=&quot;true&quot;&gt;
				&lt;param name=&quot;controller&quot; value=&quot;true&quot;&gt;</xsl:text>
			</object>
		</xsl:when>
		<xsl:otherwise> 
			<p>A file preview is not available.</p>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

Feb 11, 2013 at 12:47 PM
How about an example of how to use!
Feb 11, 2013 at 1:53 PM
Usage:
<xsl:call-template name="EmbeddedFilePreview">
    <xsl:with-param name="FileType" select="@File_x0020_Type"/>
    <xsl:with-param name="FilePath" select="@FileRef"/>
    <xsl:with-param name="paramHeight" select="500"/>
    <xsl:with-param name="paramWidth" select="1000"/>
    <xsl:with-param name="curr_Site" select="$curr_Site" />
</xsl:call-template>
Apr 10, 2013 at 7:25 AM
Hi,
Can you please show me how to use this.

Any basic tutorial will be highly appreciated. I am a basic learner.

Thanks.
Apr 15, 2013 at 7:08 AM
Edited Apr 15, 2013 at 7:10 AM
I always get "a file preview is not available " message whenever try to get a preview using the above code.
any help or tutorial like stuffs will be much appreciated.
Apr 16, 2013 at 3:28 PM
@masbaaz and @TaffyLewis

Can you post your code that you are using as well as the file types you are trying to embed? Keep in mind that this doesn't work for all file types as there are only a few that you can embed into a web page.

Cheers,
Matthew