简体   繁体   English

sharepoint webpart 与 caml 和 xslt

[英]sharepoint webpart with caml and xslt

How can i create a sharepoint webpart that accesses a List, and that can have CAML applied to it.我如何创建一个 sharepoint webpart 来访问一个列表,并且可以应用 CAML。

The CAML is needed to display return only list items that have the field with "Position" > 0需要 CAML 来显示仅返回具有“位置”> 0 字段的列表项

i also need the webpart to have xslt applied to that.我还需要 webpart 应用 xslt。

You need to add the Content Query Web Part to your page (note: requires MOSS not free WSS).您需要将内容查询 Web 部分添加到您的页面(注意:需要 MOSS 而不是免费的 WSS)。 This allows you to query your data and apply an XSL transform to it.这允许您查询数据并对其应用 XSL 转换。

The web part allows you to query a particular site collection, web or list. web 部分允许您查询特定网站集、web 或列表。 You can then set parameters to return data of a certain type and apply filters, sorting and grouping.然后您可以设置参数以返回特定类型的数据并应用过滤器、排序和分组。 You can also choose how you wish the data to be displayed which appears to the end user as a dropdown list of options.您还可以选择您希望数据的显示方式,最终用户将以选项下拉列表的形式显示这些数据。 Each of these options is powered by an XSL transform.这些选项中的每一个都由 XSL 转换提供支持。

This blog post by Heather Solomon is one of the best resources to help you get started with how to create your own transform and configure the CQWP. Heather Solomon 的这篇博文是帮助您开始创建自己的转换和配置 CQWP 的最佳资源之一。 It also explains how to ensure all the fields you need are passed through to the XSLT (by default this only happens for a small subset).它还解释了如何确保将您需要的所有字段都传递给 XSLT(默认情况下,这只会发生在一小部分)。

Update:更新:

To only return list items where the field "Position" > 0, it is simplest to do this within XSLT as well.要仅返回字段“位置”> 0 的列表项,最简单的方法也是在 XSLT 内执行此操作。 You must have added the Position field to CommonViewFields so that it gets passed through to the XSLT. Then in your custom item style (in ItemStyle.xsl if you follow Heather's post), add the following:您必须已将 Position 字段添加到 CommonViewFields,以便它传递到 XSLT。然后在您的自定义项样式中(如果您遵循 Heather 的帖子,则在 ItemStyle.xsl 中)添加以下内容:

<xsl:if test="@Position &gt; 0">
  <!-- Display desired row output -->
</xsl:if>

This implicitly ignores when "Position" <= 0.当“位置”<= 0 时,这会隐式忽略。

I agree with Alex, that the Content Query Web Part (CQWP) is the way to go if possible.我同意亚历克斯的观点,如果可能的话,内容查询 Web 部分 (CQWP) 是通往 go 的途径。

However, if you want to get into the code you can do something like the following.但是,如果您想深入了解代码,您可以执行如下操作。 The rough part is getting it into XML, although there may be an easy way to get it into some non-custom (albeit ugly) form of XML.粗略的部分是将它变成 XML,尽管可能有一种简单的方法可以将它变成 XML 的一些非自定义(尽管丑陋)形式。

SPList list = web.Lists["My List Name"];
SPView view = list.Views["My View Name"];  // This view would define Postion > 0
SPQuery query = new SPQuery(view);
SPListItemCollection items = list.GetItems(query);

// Iterate through results and generate XML

If you don't want to use an existing view, you will need to set up the SPQuery object by hand;如果不想使用现有视图,则需要手动设置 SPQuery object; setting its ViewFields, Query, and RowLimit at a minimum.将其 ViewFields、Query 和 RowLimit 设置为最低限度。 You can use the a CAML Query Tool to help you with this.您可以使用CAML 查询工具来帮助您完成此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM