Sharepoint 2010 xsl @PublishingPageImage在列表Web部件中显示空白文本

时间:2014-02-14 21:11:46

标签: xslt sharepoint sharepoint-2010

我正在为网站实施自定义新闻摘录列表视图。它有4个字段,

  • 标题
  • 短篇文章
  • 完整文章的网址
  • 图像

目前,我已经成功地使用列表编辑表单中的4个基本文本字段使其看起来正确,但是,Sharepoint中有一个功能允许用户使用内置浏览器从服务器中选择已发布的图像。然后将该图像作为html存储在“PublishingPageImage”字段中。但是,我意识到,由于某种原因,任何带有html的字段都会返回为空白,当我将基本URL文本字段切换为已发布的图像类型时,就会发生这种情况。此外,使用Sharepoint的超链接字段类型不再显示链接html。

我尝试在网络上使用了很多建议的方法,然而,他们都在网络部分为我抛出错误。

    Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Microsoft SharePoint Foundation-compatible HTML editor such as Microsoft SharePoint Designer. If the problem persists, contact your Web server administrator.


    Correlation ID:ae8f04be-849f-454f-843a-d2f7487b31d8

对我的代码的任何建议都会受到赞赏,我对xsl的世界相当新。 Sharepoint Designer似乎显示xsl没有问题。

<!--
This section is the set up and can be used at the top of any external XSLT stylesheet file
-->
<xsl:stylesheet
xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
version="1.0"
exclude-result-prefixes="xsl msxsl ddwrt"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<!--
End of Set Up
-->
<!--
The initial template which in this case is matching everything with "/"
It then creates a variable called Rows - this is accessed as $Rows
A standard HTML table and header row with the names of our columns is next followed by a loop through each row of the list and calls our second template dvt1-rowview to display the contents
-->
<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema">
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
<link rel="stylesheet" type="text/css" href="/Transportation/Styles/styles.css" />
<ul class="section-list">
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview" />
</xsl:for-each>
</ul>
</xsl:template>
<!--
End of first template
-->
<!--
Standard HTML rows and cells contain the contents of our list row
xsl:value-of command is used to display our columns
Columns are accessed as @InternalColumnName
-->
<xsl:template name="dvt_1.rowview">
<li>

<xsl:if test="@PublishingPageImage != ''">
        <xsl:value-of select="@PublishingPageImage" disable-output-escaping="yes"/>
</xsl:if>

<h3><xsl:value-of select="@Title" /></h3>
<p><xsl:value-of select="@Short_Content"/></p>


<p><xsl:value-of select="@Link" disable-output-escaping="yes"/></p>
</li>
</xsl:template>
</xsl:stylesheet>

2 个答案:

答案 0 :(得分:2)

显示图片

获取img src中图像的列值,如下例所示

<xsl:variable name="url" >
     <xsl:value-of select="@PublishingPageImage" disable-output-escaping="yes"/>
  </xsl:variable>
<xsl:variable name="imglink" select="substring-before($url,',')" > </xsl:variable>
<div class="image"><img src="{$imglink}" width="296px;" height="200px;"></img></div>

答案 1 :(得分:1)

事实证明,问题不在于xslt,它只是一个分享点怪癖。如果有人遇到同样的问题,我会回答这个问题。

正如我之前提到的,我使用的是List Web部件,XSLT用于List View或XLV。要将图像添加到我想要的列表视图中,首先,我将页面图像(它也可以是另一个发布图像字段)添加到列表本身。然后我将它添加到我在网页上显示的列表视图中。然后,在列表的Web部件设置中,我不得不再次将Web部件指向更新的列表视图。此时,Sharepoint本身可能会生成自己的xsl缓存,这就是为什么在修改列表视图时我必须再次将其指向列表视图的原因。

我发现有助于解决此问题的一个很好的小片段是:

<xsl:for-each select="@*">
    <xsl:value-of select="name()"/>
    <xsl:text> = </xsl:text>
    <xsl:value-of select="."/><br/>
</xsl:for-each> 

来源:http://benprins.wordpress.com/2012/05/20/show-all-fields-and-values-with-xslt/

当嵌套在行模板中时,它会为每行提供每个字段名称和值。如果您想检查并查看您的字段是否显示,或者找到字段的特定名称,或者

,这是很好的