zoukankan      html  css  js  c++  java
  • 总结:SharePoint Designer 2010 DVWP (6) DataFormWebPart  Sort and Group

         有时data view webpart在下次打开时就看不到图形界面了,这个时候“Options”里的“Sort & Group”是不可用的,此时就要直接写<xsl:sort select=”” order=”” data-type=””/>

    Used within an <xsl:for-each> to determine the sort order in which the nodeset (group of rows) are processed.

    <xsl:sort> allows you to change the default sort order of the items as they are displayed in a Data View Web Part (DVWP).  By default (in almost all cases), the items will be displayed in ID number order. This is rarely useful, so in most cases you will want to indicate your own sort order.

    <xsl:sort> is used within the <xsl:for-each> tag.  This is because the sorting occurs on the entire rowset before the individual rows are displayed.

    In the simple example we’ve been using, you don’t see an <xsl:sort>.  This is because when you first add a DVWP to the page, you haven’t yet specified a sort order:

    <XSL>

     <xsl:stylesheet xmlns:x=""

        <a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>" xmlns:d="<a href="http://schemas.microsoft.com/sharepoint/dsp">http://schemas.microsoft.com/sharepoint/dsp</a>" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="<a href="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">http://schemas.microsoft.com/WebParts/v2/DataView/runtime</a>" xmlns:asp="<a href="http://schemas.microsoft.com/ASPNET/20">http://schemas.microsoft.com/ASPNET/20</a>" xmlns:__designer="<a href="http://schemas.microsoft.com/WebParts/v2/DataView/designer">http://schemas.microsoft.com/WebParts/v2/DataView/designer</a>" xmlns:xsl="<a href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</a>" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">

     

        <xsl:output method="html" indent="no"/>

        <xsl:decimal-format NaN=""/>

        <xsl:param name="dvt_apos">'</xsl:param>

        <xsl:variable name="dvt_1_automode">0</xsl:variable>

     

        <xsl:template match="/">

          <xsl:call-template name="dvt_1"/>

        </xsl:template>

     

        <xsl:template name="dvt_1">

          <xsl:variable name="dvt_StyleName">Table</xsl:variable>

          <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>

          <table border="0" width="100%" cellpadding="2" cellspacing="0">

            <tr valign="top">

              <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">

                <th width="1%" nowrap="nowrap"></th>

             </xsl:if>

              <th nowrap="nowrap">Title</th>

            </tr>

            <xsl:call-template name="dvt_1.body">

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

            </xsl:call-template>

          </table>

        </xsl:template>

     

        <xsl:template name="dvt_1.body">

          <xsl:param name="Rows"/>

          <xsl:for-each select="$Rows">

            <xsl:call-template name="dvt_1.rowview"/>

          </xsl:for-each>

        </xsl:template>

     

        <xsl:template name="dvt_1.rowview">

          <tr>

            <xsl:if test="position() mod 2 = 1">

              <xsl:attribute name="class">ms-alternating</xsl:attribute>

            </xsl:if>

            <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">

              <td width="1%" nowrap="nowrap">

                <span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>

              </td>

            </xsl:if>

            <td>

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

            </td>

          </tr>

        </xsl:template>

     </xsl:stylesheet>

    </XSL>

    If you do want to specify a sort order, you add the <xsl:sort> within the <xsl:for-each>, as I mentioned above. In this example, the rows (items) will just be sorted by the values in the Title column:

    <xsl:template name="dvt_1.body">

     <xsl:param name="Rows"/>

     <xsl:for-each select="$Rows">

        <xsl:sort select="@Title" />

        <xsl:call-template name="dvt_1.rowview"/>

     </xsl:for-each>

    </xsl:template>

     

    In the simplest case, you just add the column(s) you want to sort by and you are all set.  However, there are several other attributes it’s important to know about:

     

    Attribute

    Values

    Description

    select

    XPath expression

    The select can take the form of any value XPath expression. Most often, you’ll just specify a column name.  Sometimes you may want to sort by a calculated value or a value in another list, and you can specify those expressions as well.

    order

    [ascending | descending]

    This setting determines whether the sort is A-Z or Z-A.

    data-type

    [text | number]

    Data-type lets you specify what type of value the select contains.  This is most often useful when you’d like to treat numbers as numbers rather than as text.

    lang

    language-code

    Specify the language if you want the sort to be “language-aware”.

    case-order

    [upper-first | lower-first]

    In the instance where the values are of mixed case, this setting identifies how to treat capital vs. lower case characters.

    I’ve never had the need to specify the lang or case-order attributes myself, but it’s good to know about them.

    You can have multiple <xsl:sort> tags in your <xsl:for-each>.  The <xsl:sort> tags are simply executed in order, giving you the ability to have primary, secondary, tertiary, etc., sorts.  For instance, the following example shows how you might generate a list of event attendees, sorted by LastName and then FirstName so that you could take attendance as people arrive:

    <xsl:template name="dvt_1.body">

     <xsl:param name="Rows"/>

     <xsl:for-each select="$Rows">

        <xsl:sort select="@LastName" />

        <xsl:sort select="@FirstName" />

        <xsl:call-template name="dvt_1.rowview"/>

     </xsl:for-each>

    </xsl:template>

     

    If you want to sort by a value that is in a different list, you need to specify the appropriate XPath expression.  At this point, you’re leaving the warm and comfy zone of the SharePoint Designer dialogs and you’ll need to write the XPath expression yourself.  Let’s say that you have two lists, one with one item per sale, and the other with total sales by region.  Assuming that you’ve set up your DataSource to contain both lists (you can have many more than two lists in a DVWP), the XPath expression might look something like this:

    <xsl:sort select="/dsQueryResponse/List2/Rows/Row[@Region = current()/@Region]/@TotalSales" order="descending" />

     

    This will display the individual sales sorted by the highest sales per region.

    Come from: http://www.endusersharepoint.com/2010/02/16/unlocking-the-mysteries-of-data-view-web-part-xsl-tags-part-8-xslsort/

  • 相关阅读:
    使用duilib链接错误 _declspec(dllimport)
    USB磁盘VID和PID 对应到次盘盘符相关文章
    路径拆分函数
    COM问题
    将对话框嵌入父窗体
    duilib的caption上的Edit无法激活
    LoadLibrary失败,GetLastError MOD_NOT_FOUND
    windows字符串
    windows界面库种类
    windows插件框架
  • 原文地址:https://www.cnblogs.com/LeimOO/p/2064048.html
Copyright © 2011-2022 走看看