SharePoint视图XSLT的位置都放在Layouts/XSL目录下,主要用到三个文件
main.xsl
vwstyles.xsl
fldtypes.xsl
我们需要创建一个自定义的xsl如sample.xsl重载Xslt的一些关键模板,达到更改界面显示的目的。
找到fldtypes.xsl, PrintField节点是显示字段模板的
<xsl:template name="PrintField" ddwrt:dvt_mode="body" ddwrt:ghost="always"> <xsl:param name="thisNode" select="."/> <xsl:param name="Position" select="1" /> <xsl:param name="Type" select="string(@Type)"/> <xsl:param name="Name" select="string(@Name)"/> <xsl:param name="folderUrlAdditionalQueryString"/> <xsl:choose> <xsl:when test="$Type='DateTime'"> <xsl:apply-templates select="." mode="DateTime_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Type='Computed'"> <xsl:choose> <xsl:when test="$Name='LinkTitle' or $Name='LinkTitleNoMenu'"> <xsl:apply-templates select="." mode="Computed_LinkTitle_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Name='LinkFilename' or $Name='LinkFilenameNoMenu'"> <xsl:apply-templates select="." mode="Computed_LinkFilename_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Name='DocIcon'"> <xsl:apply-templates select="." mode="Computed_DocIcon_body"> <xsl:with-param name="thisNode" select="$thisNode"/> <xsl:with-param name="folderUrlAdditionalQueryString" select="$folderUrlAdditionalQueryString"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Name='NameOrTitle'"> <xsl:apply-templates select="." mode="Computed_NameOrTitle_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Name='URLwMenu'"> <xsl:apply-templates select="." mode="Computed_URLwMenu_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Name='HealthReportSeverityIcon'"> <xsl:apply-templates select="." mode="Computed_HealthReportSeverityIcon_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Name='LinkDiscussionTitle' or $Name='LinkDiscussionTitleNoMenu'"> <xsl:apply-templates select="." mode="Computed_LinkDiscussionTitle_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Name='Threading' or $Name='BodyAndMore'"> <xsl:apply-templates select="." mode="Computed_body"> <xsl:with-param name="thisNode" select="$thisNode" /> <xsl:with-param name="Position" select="$Position" /> </xsl:apply-templates> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="." mode="Computed_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:when test="$Type='Attachments'"> <xsl:apply-templates select="." mode="Attachments_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Type='User' or $Type='UserMulti'"> <xsl:apply-templates select="." mode="User_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Type='Note'"> <xsl:apply-templates select="." mode="Note_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Type='Text'"> <xsl:apply-templates select="." mode="Text_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Type='Number' or $Type='Currency'"> <xsl:apply-templates select="." mode="Number_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Type='Lookup' or $Type='LookupMulti' or $Type='WorkflowStatus'"> <xsl:apply-templates select="." mode="Lookup_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Type='URL'"> <xsl:apply-templates select="." mode="URL_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Type='CrossProjectLink'"> <xsl:apply-templates select="." mode="CrossProjectLink_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Type='Recurrence'"> <xsl:apply-templates select="." mode="Recurrence_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$Type='AllDayEvent'"> <xsl:apply-templates select="." mode="AllDayEvent_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:when test="@CAMLRendering='TRUE'"> <xsl:apply-templates select="." mode="CAMLRendering_body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="." mode="body"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:template>
所以如果我们完全不想要SharePoint自带这么复杂的计算,可以这样写
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> <xsl:import href="/_layouts/xsl/main.xsl"/> <xsl:template mode="Item" match="Row"> <xsl:param name="Fields" select="."/> <xsl:param name="Collapse" select="."/> <xsl:param name="Position" select="1" /> <xsl:param name="Last" select="1" /> <xsl:variable name="thisNode" select="."/> <xsl:for-each select="$Fields"> <xsl:value-of select="$thisNode/@*[name()='FileRef']"/> </xsl:for-each> </xsl:template> <xsl:template match="View" mode="full"> <tr> <td> <xsl:apply-templates select="." mode="RenderView" /> <xsl:apply-templates mode="footer" select="." /> </td> </tr> </xsl:template> <xsl:template match="View" mode="RenderView"> <xsl:variable name="Fields" select="ViewFields/FieldRef[not(@Explicit='TRUE')]"/> <xsl:variable name="Groups" select="Query/GroupBy/FieldRef"/> <xsl:variable name="Collapse" select="Query/GroupBy[@Collapse='TRUE']"/> <xsl:variable name="GroupCount" select="count($Groups)"/> <xsl:for-each select="$AllRows"> <xsl:variable name="thisNode" select="."/> <xsl:variable name="Position" select="position()" /> <xsl:apply-templates mode="Item" select="$thisNode"> <xsl:with-param name="Fields" select="$Fields"/> <xsl:with-param name="Collapse" select="$Collapse"/> <xsl:with-param name="Position" select="position()"/> <xsl:with-param name="Last" select="last()"/> </xsl:apply-templates> </xsl:for-each> </xsl:template> </xsl:stylesheet>