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

系统 2200 0

很抱歉,本来是有截图的,可以让过程看得更清楚些,但可能由于机器的原因,图片始终无法上传.所以只能写文字版了!
    在
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.xsl ContentQueryMain.xsl SummaryLinkMain.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="*" 将这个名为 Default template 复制一份,将 name 属性修改为 AnnouceList match 属性修改为 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 "。点击“确定”按钮。

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


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论