xslt table fixed columns - linux

This is my xslt table code. I would like to have fixed columns for name, size date. I want to control the widths of these columns in the code without having the columns size according to data. Thanks.
<h1><table border="0">
<tr bgcolor="#1E90ff">
<th>Name</th>
<th>Size</th>
<th>Date</th>
</tr>
<xsl:for-each select="list/*">
<xsl:sort select="#mtime"/>
<xsl:variable name="name">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:variable name="size">
<xsl:if test="string-length(#size) > 0">
<xsl:if test="number(#size) > 0">
<xsl:choose>
<xsl:when test="round(#size div 1024) < 1"><xsl:value-of select="#size" /></xsl:when>
<xsl:when test="round(#size div 1048576) < 1"><xsl:value-of select="format-number((#size div 1024), '0.0')" />K</xsl:when>
<xsl:otherwise><xsl:value-of select="format-number((#size div 1048576), '0.00')" />M</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:variable>
<xsl:variable name="date">
<xsl:value-of select="substring(#mtime,9,2)"/>-<xsl:value-of select="substring(#mtime,6,2)"/>-<xsl:value-of select="substring(#mtime,1,4)"/><xsl:text> </xsl:text>
<xsl:value-of select="substring(#mtime,12,2)"/>:<xsl:value-of select="substring(#mtime,15,2)"/>:<xsl:value-of select="substring(#mtime,18,2)"/>
</xsl:variable>
<tr>
<td valign='top'><img src='/.icons/unknown.gif' alt='[ ]' width='16' height='16' /><xsl:value-of select="."/></td>
<td align="left"><xsl:value-of select="$size"/></td>
<td><xsl:value-of select="$date"/></td>
</tr>
</xsl:for-each>
</table></h1>

This was what I was looking for
<tr>
<th width="70%">Name</th>
<th width="19%">Size</th>
<th width="11%">Date</th>
</tr>

Related

Filtering based on dropdown in DVWP

I have created a DVWP dropdown for filtering a list which I've shown using a DVWP. I've set an year list as the dropdown DVWP data source and on selecting a year, i wanna filter the list DVWP to show the items filtered by year.
The dropdown:
<select name="ID" size="1"
onchange="document.location.href='http://server/site.aspx' + '?' + 'year' + '=' + this.options[selectedIndex].value">.
I've added a QueryString parameter param1 which takes its value from Year to this dropdown as well as the list DVWP. In the list DVWP, I've added a filter condition which is: Year equals [Param1]. Note: Year here is a calculated column which gets year from a date field.
My question is even though the dropdown gets post back after selecting a value, it doesn't get filtered. What have I done wrong in this? I've been racking my brains on this but I can't get this to work no matter what I try. Please help.
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">Table</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<xsl:variable name="dvt_FieldNameNoAtSign" select="substring-after($dvt_filterfield, '#')" />
<xsl:variable name="dvt_FilteredRowsText" select="$Rows[.=$dvt_filterval or ($dvt_filtertype='date' and substring-before($dvt_filterval,'T') = substring-before(.,'T'))]" />
<xsl:variable name="dvt_FilteredRows" select="$Rows[normalize-space(*[name()=$dvt_filterfield])=$dvt_filterval or ($dvt_filtertype='date' and substring-before($dvt_filterval,'T') = substring-before(normalize-space(*[name()=$dvt_filterfield]),'T'))]" />
<xsl:variable name="dvt_FilteredRowsAttr" select="$Rows[normalize-space(#*[name()=$dvt_FieldNameNoAtSign])=$dvt_filterval or ($dvt_filtertype='date' and substring-before($dvt_filterval,'T') = substring-before(normalize-space(#*[name()=$dvt_FieldNameNoAtSign]),'T'))]" />
<xsl:variable name="dvt_RowCount">
<xsl:choose>
<xsl:when test="$dvt_adhocfiltermode != 'query' and $dvt_filterfield">
<xsl:choose>
<xsl:when test="starts-with($dvt_filterfield, '#')"><xsl:value-of select="count($dvt_FilteredRowsAttr)" /></xsl:when>
<xsl:when test="$dvt_filterfield = '.'"><xsl:value-of select="count($dvt_FilteredRowsText)" /></xsl:when>
<xsl:otherwise><xsl:value-of select="count($dvt_FilteredRows)" /></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:value-of select="count($Rows)" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="RowLimit" select="10" />
<xsl:variable name="FirstRow" select="$dvt_firstrow" />
<xsl:variable name="LastRow">
<xsl:choose>
<xsl:when test="($FirstRow + $RowLimit - 1) > $dvt_RowCount"><xsl:value-of select="$dvt_RowCount" /></xsl:when>
<xsl:otherwise><xsl:value-of select="$FirstRow + $RowLimit - 1" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="IsEmpty" select="$dvt_RowCount = 0 or $RowLimit = 0" />
<xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0"/>
<xsl:call-template name="dvt_1.toolbar">
<xsl:with-param name="Rows" select="$Rows" />
</xsl:call-template>
<xsl:choose>
<xsl:when test="$dvt_IsEmpty">
<xsl:call-template name="dvt_1.empty"/>
</xsl:when>
Is this what you were looking for?
Umm, if this helps, in the list that I'm using to populate the dropdown, the 'Year' field has an internal name #Title. Would that have something to do with this?
<xsl:template name="dvt_1.rowview">
<option>
<xsl:value-of select="#Title" />
</option>
</xsl:template>
. But it also has #Year, so not sure which is which.
<td class="ms-vb">
<xsl:value-of select="#Year"/>
</td>
Oops, sorry for confusing. The 2nd #Year is the calculated column which I'd created.
UPDATE 2: The code you'd requested:
<td class="ms-toolbar" nowrap="nowrap">
<xsl:call-template name="dvt.filterfield">
<xsl:with-param name="fieldname">#Year</xsl:with-param>
<xsl:with-param name="fieldtitle">Year</xsl:with-param>
<xsl:with-param name="Rows" select="$Rows" />
<xsl:with-param name="fieldtype">text</xsl:with-param>
</xsl:call-template>
Something like this has been created for both the dvwp's:
<xsl:param name="ListID">{6889CA36-79AC-4FA8-9F0A-C013C944B3C5}</xsl:param>
<xsl:param name="Param1" />
I just noticed(thanks to a colleague of mine) that Year which is a calculated column is as a string. So, for 2013, it was storing it as 2,013 because of which I couldn't filter the DVWP properly. I used =TEXT(([columnname], "yyyy") instead of YEAR([colname]) and everything worked fine.
If your parameter name is called param1, then I believe your dropdown will need to pass a query string parameter called "param1" into the URL instead of "year". Could you try modifying that select tag to be like this?:
<select name="ID" size="1"
onchange="document.location.href='http://server/site.aspx?param1='
+ this.options[selectedIndex].value">

SharePoint 2010: How do I use the 'onmouseover' attribute in the ItemStyle.XSL file for the Content Query Webpart?

I'm currently working in SharePoint 2010, with the Content Query Webpart.
I just want to show a list, but when the user hovers the mouse over the item, I want him/her to see a description. I have tried to put the 'onmouseover' attribute everywhere, but nothing seems to work.
This is my code so far:
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayTitle">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#Title"/>
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="Description">
<xsl:value-of select="#Description" />
</xsl:variable>
<xsl:variable name="Start">
<xsl:value-of select="ddwrt:FormatDateTime(string(#Start), 1033, 'H:mm')" />
</xsl:variable>
<xsl:variable name="End">
<xsl:value-of select="ddwrt:FormatDateTime(string(#End), 1033, 'H:mm')" />
</xsl:variable>
<xsl:variable name="Speaker">
<xsl:value-of select="#Speaker" />
</xsl:variable>
<xsl:variable name="tableStart">
<xsl:if test="$CurPos = 1">
<![CDATA[
<table border=1 bgcolor=#CCFFFF>
<tr>
<td><b>Start</b></td>
<td><b>End</b></td>
<td><b>Title</b></td>
<td><b>Speaker</b></td>
</tr>
]]>
</xsl:if>
</xsl:variable>
<xsl:variable name="tableEnd">
<xsl:if test="$CurPos = $Last">
<![CDATA[ </table> ]]>
</xsl:if>
</xsl:variable>
<xsl:comment>Start of HTML section</xsl:comment>
<xsl:value-of select="$tableStart" disable-output-escaping="yes"/>
<tr>
<td><b> <xsl:value-of select="$Start"/> </b></td>
<td><b> <xsl:value-of select="$End"/> </b></td>
<td style="width:500px"><b> <xsl:value-of select="$DisplayTitle"/></b></td>
<td> <xsl:attribute name="onmouseover"> <xsl:value-of select="#Description"/> </xsl:attribute> </td>
<td><b> <xsl:value-of select="$Speaker"/> </b></td>
</tr>
<xsl:value-of select="$tableEnd" disable-output-escaping="yes"/>
Where do I put the 'onmouseover' attribute so that when your mouse hovers over an item, it shows the description?
Thanks in advance.

MOSS Content Query Web part itemstyle.xsl

I have a Content Query Webpart (CQWP) pulling the URL and title from a News links list. The CQWP uses the XSLT style Orange.News.Links defined in ItemStyle.xsl.
I need to sort the title #Title0 field as commented out below because it causes an error.
Does anyone know whats causing this error? - Many Thanks. The XSLT code is below:
<xsl:template name="Orange.News.Links" match="Row[#Style='Orange.News.Links']" mode="itemstyle">
<xsl:param name="CurPos" />
<xsl:param name="Last" />
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayTitle">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#URL"/>
<xsl:with-param name="UrlColumnName" select="'URL'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="LinkTarget">
<xsl:if test="#OpenInNewWindow = 'True'" >_blank</xsl:if>
</xsl:variable>
<xsl:variable name="SafeImageUrl">
<xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
<xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="Header">
<xsl:if test="$CurPos = 1">
<![CDATA[<ul class="list_Links">]]>
</xsl:if>
</xsl:variable>
<xsl:variable name="Footer">
<xsl:if test="$Last = $CurPos">
<![CDATA[</ul>]]>
</xsl:if>
</xsl:variable>
<xsl:value-of select="$Header" disable-output-escaping="yes" />
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="substring-before($DisplayTitle,', ')"></xsl:value-of>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="#Description"/>
</xsl:attribute>
<!-- <xsl:sort select="#Title0"/> -->
<xsl:value-of select="#Title0">
</xsl:value-of>
</a>
</li>
<xsl:value-of select="$Footer" disable-output-escaping="yes" />
</xsl:template>
I need to sort the title #Title0 field
as commented out below because it
causes an error.
Does anyone know whats causing this
error?
Yes, <xsl:sort/> can only be a child node of either <xsl:apply-templates> or <xsl:for-each> (and of <xsl:perform-sort> in XSLT 2.0).
Recommendation: Take at least a mini-course in XSLT and XPath so that you at least grok the fundamental concepts.

SharePoint XSLT Problem -

I am trying to do some highlighting on some SharePoint XSLT Results. BElow is the XML that i am getting.
The Problem that i am getting is that the Template Match blocks are not matching the child nodes of UM If someone can see where i am going wrong that woould be great.
Thank you
Chhris
<rows>
<row>
<LastModifiedTime>02/25/2010 18:32:25</LastModifiedTime>
<RANK>325</RANK>
<TITLE>UMUK Win At The Mobile Entertainment</TITLE>
<AUTHOR>SVR08-002\Administrator</AUTHOR>
<CREATED>02/25/2010 18:32:22</CREATED>
<PATH>http://svr08-002:7005/Lists/FrontPageNews/DispForm.aspx?ID=3</PATH>
<HitHighlightedSummary>a
<c0>UM</c0> UK won the category of Best Music Label 2009 at the 4th annual ME (Mobile Entertainment) Awards C <ddd/>
</HitHighlightedSummary>
</row>
</rows>
and here is the XSLT that i have so far.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<table class="ICS_SearchTable" cellpadding="0" cellspacing="0" width="100%">
<xsl:for-each select="rows/row">
<xsl:variable name="Ext">
<xsl:call-template name="get-file-extension">
<xsl:with-param name="path" select="substring-before(PATH, '?')" />
</xsl:call-template>
</xsl:variable>
<tr>
<td width="10%">
</td>
<td>
<div class="ICS_SearchResultItem">
<div class="ICS_SearchResultItemImage">
<img src="/Style Library/UMIGlobe/Styles/Images/Common/umgi-{$Ext}.png" alt="{$Ext}"/>
</div>
<div class="ICS_SearchResultItemTitle">
<xsl:value-of select="TITLE"/>
</div>
<div class="ICS_SearchResultItemDesc">
<xsl:choose>
<xsl:when test="HitHighlightedSummary[. != '']">
<xsl:call-template name="HitHighlighting">
<xsl:with-param name="hh" select="HitHighlightedSummary" />
</xsl:call-template>
</xsl:when>
<xsl:when test="DESCRIPTION[. != '']">
<xsl:value-of select="DESCRIPTION"/>
</xsl:when>
</xsl:choose>
</div>
<div class="ICS_SearchResultItemLink">
<xsl:value-of select="PATH"/> - <xsl:value-of select="AUTHOR" /> - <xsl:value-of select="LastModifiedTime"/>
<xsl:call-template name="DisplaySize">
<xsl:with-param name="size" select="SIZE" />
</xsl:call-template>
</div>
</div>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name="HitHighlighting">
<xsl:param name="hh" />
<xsl:apply-templates select="$hh"/>
</xsl:template>
<xsl:template match="ddd">
…
</xsl:template>
<xsl:template match="c0">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c1">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c2">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c3">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c4">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c5">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c6">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c7">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c8">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<xsl:template match="c9">
<b>
<xsl:value-of select="."/>
</b>
</xsl:template>
<!-- The size attribute for each result is prepared here -->
<xsl:template name="DisplaySize">
<xsl:param name="size" />
<xsl:if test='string-length($size) > 0'>
<xsl:if test="number($size) > 0">
-
<xsl:choose>
<xsl:when test="round($size div 1024) < 1"><xsl:value-of select="$size" /> Bytes</xsl:when>
<xsl:when test="round($size div (1024 *1024)) < 1"><xsl:value-of select="round($size div 1024)" />KB</xsl:when>
<xsl:otherwise><xsl:value-of select="round($size div (1024 * 1024))"/>MB</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="get-file-extension">
<xsl:param name="path" />
<xsl:choose>
<xsl:when test="contains( $path, '/' )">
<xsl:call-template name="get-file-extension">
<xsl:with-param name="path" select="substring-after( $path, '/' )" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains( $path, '.' )">
<xsl:call-template name="get-file-extension">
<xsl:with-param name="path" select="substring-after( $path, '.' )" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- SET THE PATH IMAGE SRC -->
<xsl:choose>
<xsl:when test="$path = 'uk' or $path = 'org' or $path = 'com' or $path = 'net' or $path = 'biz' or $path = 'gov'">
<xsl:text>url</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$path" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
What do you mean by "child nodes of UM"?
Maybe I'm missing something, but there are no nodes named "UM", just text. So do you mean that you want to match the node that contains the text "UM"... in other words <c0>UM</c0>?
In my case, when I run your stylesheet, it does match the <c0> node, and writes a <b> node.
<b>UM</b> UK won the category of Best Music Label 2009 at the 4th annual ME (Mobile Entertainment) Awards C
What's not working for you?

Extending Sharepoint XSL template

Thanks to this post I've come up with the following template:-
<xsl:variable name="Doc">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#DocumentLink1"/>
</xsl:call-template>
</xsl:variable>
<a href="{substring-before($Doc,',')}">
<xsl:value-of select="substring-after($Doc,',')" />
</a>
This template is nested in an unorderd list and li tag (see below). Since this code has a physical and visual presence in the html page when no content exists I would like to add the li tags and possibly the ul tags to the template. Can anyone tell me how to accomplish this?
<ul>
<li>
<xsl:variable name="Doc">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#DocumentLink1"/>
</xsl:call-template>
</xsl:variable>
<a href="{substring-before($Doc,',')}">
<xsl:value-of select="substring-after($Doc,',')"/>
</a>
</li>
<li>
<xsl:variable name="Doc">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#DocumentLink2"/>
</xsl:call-template>
</xsl:variable>
<a href="{substring-before($Doc,',')}">
<xsl:value-of select="substring-after($Doc,',')"/>
</a>
</li>
<li>
<xsl:variable name="Doc">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#DocumentLink3"/>
</xsl:call-template>
</xsl:variable>
<a href="{substring-before($Doc,',')}">
<xsl:value-of select="substring-after($Doc,',')"/>
</a>
</li>
I'm assuming from your link to the other post that you are using the Content Query Web Part here.
You need to wrap your call to this variable using XSLT header/footer techniques. Here is one of a few posts I've seen that show how this can be done with the CQWP in particular.
You could try using the xsl:if elements to conditionally output content. You can find more info on how xsl:if works # http://www.w3schools.com/xsl/xsl_if.asp or just use your favorite search engine.

Resources