修改MOSS2007内容查询部件实现自定义格式显示

很抱歉,本来是有截图的,可以让过程看得更清楚些,但可能由于机器的原因,图片始终无法上传.所以只能写文字版了!
    在
Office SharePoint Server 2007中的内容查询Web Part只支持单个列进行显示(默认为标题列),即使将列表中的列设置为富文本格式在内容查询Web Part中也显示为不带样式的文本。下面的方法将实现在内容查询Web Part中显示我们添加的列并使用样式。

1.       为通知列表添加自定义列

在本例中我们为通知添加的自定义栏名称为“显示标题”,多行文本;富文本类型。

*关键要点:如果自定义栏的名称为非英文,为了避免SPField.InternalName属性被编码需要在创建时先用英文名称代替,并须牢记该名称,我们在后面的修改均用该英文名称。创建完成后我们再将栏的名称修改为中文,此时SPField.InternalName属性并不会被修改,而维持原命名的英文名称.

2.       将内容查询WebPart导出并修改

在页面中加入一个内容查询WebPart,将其查询设置为我们刚才所修改的通知列表。通过其上下文菜单将其导出成文件。

我们用记事本打开保存到本地磁盘的.webpart文件,找到<property name="CommonViewFields" />,将其修改为:

<property name="CommonViewFields" type="string">CustomTitle,RichText;</property>其中的CustomTitle为我们上一步中添加的自定义栏的名称(第一次输入的英文名称),RichText为该栏目的类型,保存该修改。

3.       修改XSL文件

我们用SharePoint Designer打开网站(http://moss:8000),在文件夹列表中找到\Style Library\XSL Style Sheets目录,将会看到ItemStyle.xslContentQueryMain.xslSummaryLinkMain.xsl三个文件,我们将会对其进行修改

Ø                                              打开ContentQueryMain.xsl找到<xsl:template name="OuterTemplate.GetTitle">将该template定义复制,将复本的名称更改为OuterTemplate.GetCustomTitle,相应的修改如下:

<xsl:template name="OuterTemplate.GetCustomTitle">

        <xsl:param name="CustomTitle" select="@CustomTitle"/>

        <xsl:param name="UrlColumnName"/>

        <xsl:if test="string-length($CustomTitle) != 0">

            <xsl:value-of select="$CustomTitle"/>

        </xsl:if>

        <xsl:if test="string-length($CustomTitle) = 0">

            <xsl:if test="$UseCopyUtil = 'True'">

                <xsl:value-of select="$BlankTitle" />

            </xsl:if>

            <xsl:if test="$UseCopyUtil != 'True'">

                <xsl:call-template name="OuterTemplate.GetPageNameFromUrl">

                    <xsl:with-param name="UrlColumnName" select="$UrlColumnName"/>

                </xsl:call-template>

            </xsl:if>

        </xsl:if>

</xsl:template>

保存修改。

Ø   打开SummaryLinkMain.xsl文件找到<xsl:template name="OuterTemplate.GetTitle">将该template复制,将复本的名称更改为GetCustomTitle,相应的修改如下:

    <xsl:template name="OuterTemplate.GetCustomTitle">

        <xsl:param name="CustomTitle" select="@CustomTitle"/>

        <xsl:value-of select="$CustomTitle"/>

</xsl:template>

保存修改。

Ø  打开ItemStyle.xsl文件,我们需要在该文件中加入一个样式定义

找到<xsl:template name="Default" match="*" 将这个名为Defaulttemplate复制一份,将name属性修改为AnnouceListmatch属性修改为Row[@Style=’AnnouceList’]。并在variable中加入在上一步骤中加入的自定义栏的定义,并命名为CustomTitle(见下文示例)。

修改后的template定义为:

        <xsl:template name="AnnouceList" match="Row[@Style= AnnouceList]" mode="itemstyle">

        <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="SafeImageUrl">

            <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">

                <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>

            </xsl:call-template>

        </xsl:variable>

        <xsl:variable name="CustomTitle">

            <xsl:call-template name="OuterTemplate.GetCustomTitle">

                <xsl:with-param name="Title" select="@CustomTitle"/>

                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>

            </xsl:call-template>

        </xsl:variable>

        <xsl:variable name="LinkTarget">

            <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>

        </xsl:variable>

        <div id="linkitem" class="item">

            <xsl:if test="string-length($SafeImageUrl) != 0">

                <div class="image-area-left">

                    <a href="{$SafeLinkUrl}" target="{$LinkTarget}">

                        <img class="image" src="{$SafeImageUrl}" alt="{@ImageUrlAltText}" />

                    </a>

                </div>

            </xsl:if>

            <div class="link-item">

            <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>    

            <table style="width:100%">

                     <tr>

                               <td style="width:100%" class="itemlink-item">

                                        <a href="{$SafeLinkUrl}" mce_href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}">

                                                 <xsl:value-of select="$CustomTitle" disable-output-escaping = "yes"/>

                                        </a>

                               </td>

                     </tr>

            </table>

             </div>

        </div>

</xsl:template>

 保存修改。

 4.       导入前面步骤修改的.webPart文件

打开网站集站点管理-web部件,将修改的.webpart文件上传,将该webpart名称设置为“公告栏”.

5.       将新加入的webpart重新加入页面,修改其webpart属性。

将项目样式设置为我们在上一步的XSL定义中的样式"AnnouceList"。点击“确定”按钮。

posted @ 2007-11-19 16:55  Francis Liang  阅读(876)  评论(1编辑  收藏  举报