Code Segment

SharePoint - What's new in csegRollUp v3

Oct 27 2005 by csegura @ 20:55

- Include List Data flag, if you enable the checkbox the xml data will include the underscore data (_ListTitle, _ListUrl, _SiteTitle, _SiteUrl, _ItemId, _ItemUrl, _ItemEdit)

- Queries

    -  CAML Query you can use a caml query to search on each list.
    -  RowLimit - maximun number of rows to return
    -  Recursive - the query recursive be made (great for Document Libraries)
    -  DebugQuery - show the xml from the query

   Special values that you can use on queries:

    [Login] - the logged user
    [UserName] - the complete user name
    [UserID] - the user ID
    [Now] - the current date and time
    [Now+x] - the current date and time + x days
    [Now-x] - the current date and time  - x days

  example:

   1:  <query>
   2:     <Where>
   3:        <And>
   4:           <Eq>
   5:              <FieldRef Name="Author" />
   6:   
   7:              <Value Type="Text">[UserName]</Value>
   8:           </Eq>
   9:   
  10:           <Eq>
  11:              <FieldRef Name="Modified" />
  12:   
  13:              <Value Type="DateTime">[Now-30]</Value>
  14:           </Eq>
  15:        </And>
  16:     </Where>
  17:   
  18:     <OrderBy>
  19:        <FieldRef Name="Modified" Ascending="False" />
  20:     </OrderBy>
  21:  </query>

   (Note, you need put all fields thats are on query in the fields property).

- CellConsumer interface, you can use an special value in queries called [CellProvider] this value is replaced with the cell value provide from other webpart.

Sample (conected to a document library)

<Where>

<Contains>

<FieldRef Name='FileRef'/>

<Value Type='Text'>[CellProvider]</Value>

</Contains>

</Where>

- CellProvider interface, you can provide a value to another webpart, any value that you wants, when rendering the xsl, you can add a __doPostBack('','Value') to provide values.

example:

   1:  <a href="javascript:__doPostBack('','{@Name}')">
   2:  <xsl:value-of select="_SiteTitle"/>
   3:  </a>

I have a Release Candidate version if somebody wants test it, please comment this post, thanks.

Comments (21)

Mini revisión del Data Viewer Web Part (parte 2)

Oct 25 2005 by csegura @ 18:12

La plantilla "dvt_1.body" es el cuerpo de la lista, tiene tres parametros, las filas "Rows" (2), la primera fila que vamos a mostrar "FirstRow" (3) y la última "LastRow" (4), mantiene unas variables con el orden en que se están mostrando los datos una para el grupo "AdHocGroupDir" (5) y otra para el orden "AdHocSortDir" (15)

   1:  <xsl:template name="dvt_1.body">
   2:  <xsl:param name="Rows"/>
   3:  <xsl:param name="FirstRow"/>
   4:  <xsl:param name="LastRow"/>
   5:  <xsl:variable name="AdHocGroupDir">
   6:      <xsl:choose>
   7:          <xsl:when test="$dvt_groupdir='desc'">
   8:          descending
   9:          </xsl:when>
  10:          <xsl:otherwise>
  11:          ascending
  12:          </xsl:otherwise>
  13:      </xsl:choose>
  14:  </xsl:variable>
  15:  <xsl:variable name="AdHocSortDir">
  16:      <xsl:choose>
  17:      <xsl:when test="$dvt_sortdir='desc'">
  18:          descending
  19:      </xsl:when>
  20:      <xsl:otherwise>
  21:      ascending
  22:      </xsl:otherwise>
  23:      </xsl:choose>
  24:  </xsl:variable>

Para cada fila de datos en "dvt_1.body" hay también una serie de variables en función de lo que seleccionemos en FrontPage, en "Ordenar y Agrupar", si mantendremos juntos los datos "KeepItemsTogether" (2), si ocultaremos los detalles "HideGroupDetail" (3) y el estilo del grupo "GroupStyle" (4) después la plantilla comprueba si la fila esta entre la primera y última fila a mostrar y comienza a dibujar cada fila.

   1:  <xsl:for-each select="$Rows">
   2:   <xsl:variable name="KeepItemsTogether" select="false()"/>
   3:   <xsl:variable name="HideGroupDetail" select="false()"/>
   4:   <xsl:variable name="GroupStyle" select="'auto'"/>
   5:   <xsl:if test=" (position() &gt;=$FirstRow and position() &lt;= $LastRow) or $KeepItemsTogether">
   6:      <xsl:if test="not($HideGroupDetail)" ddwrt:cf_ignore="1">
   7:         <TR style="display:{$GroupStyle}">

La primera columna de esta vista de tareas es el título (1) en este caso la columna esta vinculada al elemento (3 y 4) el icono de "Nuevo" (7 y 9)

   1:  <!--Título-->
   2:  <TD Class="{$IDAIHSOH}">
   3:   <a onfocus="OnLink(this)" href="{$URL_Display}?ID={@ID}" 
   4:       ONCLICK="GoToPage('{$URL_Display}?ID={@ID}');return false;" target="_self">
   5:      <xsl:value-of disable-output-escaping="no" select="@Title"/>
   6:   </a>
   7:   <xsl:if test="ddwrt:IfNew(string(@Created))">
   8:      <IMG SRC="/_layouts/3082/images/new.gif" alt="Nuevo"/>
   9:   </xsl:if>
  10:  </TD

La segunda columna es el campo "Asignado a",  si el campo esta vacio no hace nada (4 y 5) en caso contrario como es un campo tipo usuario si no se quiere mostrar la información del usuario en línea el muñequito del messenger (8) solo se dibujará el hipervínculo a la página del usuario 'UserInfo' (9)

   1:  <!--Asignado a-->
   2:  <TD Class="{$IDAIHSOH}">
   3:   <xsl:choose>
   4:      <xsl:when test="@AssignedTo=''">
   5:      </xsl:when>
   6:      <xsl:otherwise>
   7:         <xsl:choose>
   8:            <xsl:when test="''='FALSE'">
   9:               <A HREF="{ddwrt:URLLookup('UserInfo', 'AssignedTo', string(@ID))}">
  10:                  <xsl:value-of select="@AssignedTo"/>
  11:               </A>
  12:            </xsl:when>

En caso contrario,  (1) mostrará la información de usuario la condición (3) es para mostrar el muñequito a la izquierda  o a la derecha.

   1:  <xsl:otherwise>
   2:  <xsl:choose>
   3:  <xsl:when test="concat('FALSE','')='FALSE'">
   4:     <table cellpadding="0" cellspacing="0" MsoPnlId="data">
   5:        <tr>
   6:           <td style="padding-right: 3px;">
   7:               <xsl:choose>
   8:              <xsl:when test="ddwrt:UserLookup(string(@AssignedTo), 'EMail')=''">
   9:                  <img border="0" valign="middle" 
  10:                  height="12" width="12" 
  11:                  src="/_layouts/images/blank.gif"/>
  12:              </xsl:when>
  13:              <xsl:otherwise>
  14:              <img border="0" valign="middle" height="12" width="12" 
  15:              src="/_layouts/images/blank.gif" 
  16:              onload="IMNRC('{ddwrt:UserLookup(string(@AssignedTo), string($EMail))}')" 
  17:              id="imn{ddwrt:Counter()}"/>
  18:              </xsl:otherwise>
  19:              </xsl:choose>
  20:           </td>
  21:           <td style="padding-top: 1px;" class="ms-vb">
  22:           <A HREF="{ddwrt:URLLookup('UserInfo', 'AssignedTo', string(@ID))}">
  23:           <xsl:value-of select="@AssignedTo"/>
  24:           </A>
  25:           </td>
  26:        </tr>
  27:     </table>
  28:  </xsl:when>
  29:  <xsl:otherwise>
  30:     <nobr>
  31:        <span>
  32:           <A HREF="{ddwrt:URLLookup('UserInfo', 'AssignedTo', string(@ID))}">
  33:              <xsl:value-of select="@AssignedTo"/>
  34:           </A>
  35:           <img border="0" height="1" width="3" src="/_layouts/images/blank.gif"/>
  36:           <xsl:choose>
  37:              <xsl:when test="ddwrt:UserLookup(string(@AssignedTo), 'EMail')=''">
  38:                 <img border="0" height="12" width="12" src="/_layouts/images/blank.gif"/>
  39:              </xsl:when>
  40:              <xsl:otherwise>
  41:                 <img border="0" height="12" width="12" src="{$ImagesPath}blank.gif" 
  42:                 onload="IMNRC('{ddwrt:UserLookup(string(@AssignedTo), string($EMail))}')" 
  43:                 id="imn{ddwrt:Counter()}"/>
  44:              </xsl:otherwise>
  45:           </xsl:choose>
  46:        </span>
  47:     </nobr>
  48:  </xsl:otherwise>

Termina la plantilla "dvt.body"

   1:               </xsl:choose>
   2:            </xsl:otherwise>
   3:         </xsl:choose>
   4:      </xsl:otherwise>
   5:   </xsl:choose>
   6:  </TD>

La plantilla "dvt_1.toolbar" es la barra de menú que aparecerá si hemos marcado en las opciones del estilo de la vista "Mostrar la barra de herramientas", aquí podemos introducir nuevos botones con nuestras acciones (26 y 27), hay que tener en cuenta que si después de hacer cambios, cambiamos las opciones en FrontPage, nuestros cambios pueden desaparecer. Esta plantilla toma un parámetro (3) "Rows" que es usado para pasarlo a la plantilla "dvt.filterfield" si se esta filtrando la vista, aquí por ejemplo yo suelo poner en vez de "Agregar nuevo Element" "Añadir peticiones" por ejemplo.

   2:   <xsl:template name="dvt_1.toolbar">
   3:    <xsl:param name="Rows"/>
   4:    <table width="100%" cellpadding="0" cellspacing="0" border="0" MsoPnlId="data">
   5:       <tr>
   6:          <td colspan="2" class="ms-partline">
   7:          <IMG SRC="/_layouts/images/blank.gif" width="1" height="1" alt=""/>
   8:          </td>
   9:       </tr>
  10:       <tr>
  11:          <td class="ms-addnew" style="padding-bottom: 3px"><img src="/_layouts/images/rect.gif" alt=""/>
  12:          <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
  13:          ddwrt:nbsp-preserve="yes" 
  14:          disable-output-escaping="yes">
  15:          &amp;nbsp;
  16:          </xsl:text>
  17:          <a class="ms-addnew" ID="idAddNewTask" href="{$URL_New}" 
  18:              ONCLICK="javascript:NewItem('{$URL_New}', true);javascript:return false;" 
  19:              target="_self">
  20:              Agregar nuevo elemento
  21:          </a>
  22:          </td>
  23:       </tr>
  24:       <tr>
  25:          <td><IMG SRC="/_layouts/images/blank.gif" width="1" height="5" alt=""/></td>
  26:       </tr>
  27:    </table>
  28:    <xsl:if test="$dvt_adhocmode = 'filter'" ddwrt:cf_ignore="1">
  29:       <table cellSpacing="0" cellPadding="2" border="0" class="ms-toolbar" 
  30:               style="margin-left: 3px; margin-right: 5px;">
  31:          <tr>
  32:             <th nowrap="true">
  33:                <table>
  34:                   <tr>
  35:                      <td class="ms-toolbar" nowrap="true">
  36:                          <xsl:call-template name="dvt.filterfield">
  37:                              <xsl:with-param name="fieldname">@Title</xsl:with-param>
  38:                              <xsl:with-param name="fieldtitle">Título</xsl:with-param>
  39:                              <xsl:with-param name="Rows" select="$Rows"/>
  40:                              <xsl:with-param name="fieldtype">text</xsl:with-param>
  41:                          </xsl:call-template>
  42:                      </td>
  43:                   </tr>
  44:                </table>
  45:             </th>
  46:             <th nowrap="true">
  47:                <table>
  48:                   <tr>
  49:                      <td class="ms-toolbar" nowrap="true">
  50:                          <xsl:call-template name="dvt.filterfield">
  51:                              <xsl:with-param name="fieldname">@AssignedTo</xsl:with-param>
  52:                              <xsl:with-param name="fieldtitle">Asignado a</xsl:with-param>
  53:                              <xsl:with-param name="Rows" select="$Rows"/>
  54:                              <xsl:with-param name="fieldtype">text</xsl:with-param>
  55:                          </xsl:call-template>
  56:                      </td>
  57:                   </tr>
  58:                </table>
  59:             </th>
  60:             <td width="99%"></td>
  61:          </tr>
  62:       </table>
  63:    </xsl:if>
  64:  </xsl:template>

La plantilla es "dvt.headerfield"  monta los nombres de los campos (en la parte superior de la vista), usa 4 parametros, el nombre del campo "fieldname" (2), el nombre que se va a mostrar "fieldtitle" (3), si se puede ordenar por ese campo "sortable" (4) por defecto si, si el campo es un campo para indicar adjuntos "attachments" (5) por defecto no.

   1:  <xsl:template name="dvt.headerfield">
   2:    <xsl:param name="fieldname"/>
   3:    <xsl:param name="fieldtitle"/>
   4:    <xsl:param name="sortable">1</xsl:param>
   5:    <xsl:param name="attachments">0</xsl:param>
   6:    <xsl:choose>
   7:       <xsl:when test="($dvt_adhocmode = 'sort' or $dvt_fieldsort = '1')and $sortable">
   8:          <xsl:variable name="sortfield">
   9:              <xsl:choose>
  10:                  <xsl:when test="substring($fieldname, string-length($fieldname) - 5) = '(text)'">
  11:                      <xsl:value-of select="substring($fieldname, 1, string-length($fieldname) - 6)"/>
  12:                  </xsl:when>
  13:                  <xsl:when test="substring($fieldname, 1, 1) = '@'">
  14:                      <xsl:value-of select="substring($fieldname, 2)"/>
  15:                  </xsl:when>
  16:                  <xsl:otherwise>
  17:                      <xsl:value-of select="$fieldname"/>
  18:                  </xsl:otherwise>
  19:              </xsl:choose>
  20:          </xsl:variable>
  21:          <xsl:variable name="linkdir">
  22:              <xsl:choose>
  23:                  <xsl:when test="$dvt_sortfield = $sortfield and $dvt_sortdir = 'asc'">desc</xsl:when>
  24:                  <xsl:otherwise>asc</xsl:otherwise>
  25:              </xsl:choose>
  26:          </xsl:variable>
  27:          <xsl:variable name="sortText">
  28:              <xsl:choose>
  29:                  <xsl:when test="$linkdir='desc'">' + 'desc' + '</xsl:when>
  30:                  <xsl:otherwise>' + 'asc' + '</xsl:otherwise>
  31:              </xsl:choose>
  32:          </xsl:variable>
  33:          <a>
  34:             <xsl:attribute name="href">javascript: 
  35:             <xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_sortfield=
  36:                                     {',$sortfield,'};dvt_sortdir={',$sortText,'}'))"/>
  37:             ;
  38:             </xsl:attribute>
  39:             <xsl:choose>
  40:                <xsl:when test="$attachments">
  41:                   <xsl:value-of select="$fieldtitle" disable-output-escaping="yes"/>
  42:                </xsl:when>
  43:                <xsl:otherwise>
  44:                   <xsl:value-of select="$fieldtitle"/>
  45:                </xsl:otherwise>
  46:             </xsl:choose>
  47:             <xsl:if test="$dvt_sortfield = $sortfield">
  48:                <xsl:choose>
  49:                   <xsl:when test="$dvt_sortdir = 'asc'">
  50:                      <img border="0" alt="Ascendente" 
  51:                          src="{ddwrt:FieldSortImageUrl('Desc')}"/>
  52:                   </xsl:when>
  53:                   <xsl:when test="$dvt_sortdir = 'desc'">
  54:                      <img border="0" alt="Descendente" 
  55:                          src="{ddwrt:FieldSortImageUrl('Asc')}"/>
  56:                   </xsl:when>
  57:                </xsl:choose>
  58:             </xsl:if>
  59:          </a>
  60:       </xsl:when>
  61:       <xsl:otherwise>
  62:          <xsl:choose>
  63:             <xsl:when test="$attachments">
  64:                <xsl:value-of select="$fieldtitle" disable-output-escaping="yes"/>
  65:             </xsl:when>
  66:             <xsl:otherwise>
  67:                <xsl:value-of select="$fieldtitle"/>
  68:             </xsl:otherwise>
  69:          </xsl:choose>
  70:       </xsl:otherwise>
  71:    </xsl:choose>
  72:    <xsl:if test="$dvt_filterfield=$fieldname" ddwrt:cf_ignore="1">
  73:       <img alt="Filtro" src="{ddwrt:FieldFilterImageUrl('')}"/>
  74:    </xsl:if>
  75:  </xsl:template>

Comments (2)

Mini revisión del Data Viewer Web Part (parte 1)

Oct 23 2005 by csegura @ 14:21

Cuando convertimos una lista en XSLT lo que hace front page es convertirla en en un DataViewer webpart. El DVWP, es un webpart de acceso a datos que puede conectarse tanto a servicios web como a bases de datos. El DVWP encapsula una conexión con su consulta que devolverá XML <dwp:DataQuery>, un XSLT para mostrar los datos devueltos <dwp:XSL> y una serie de parámetros para realizar la consulta <dvwp:ParamBindings>.

En este caso he usado una lista de Tareas que he convertido a XSLT con frontpage.

 

   1:    <dvwp:DataQuery><![CDATA[
   2:      <udc:ConnectionInfo xmlns:udc="http://schemas.microsoft.com/data/udc" Purpose="Query">
   3:         <udcs:Location xmlns:udcs="http://schemas.microsoft.com/data/udc/soap">STSDataAdapter</udcs:Location>
   4:         <soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   5:            <dsp:queryRequest xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp">
   6:               <dsp:dsQuery select="/list[@id='{618BB7FE-3CB6-4255-AC10-6485EAD01F73}']" 
			resultContent="Both" resultRoot="Rows" resultRow="Row" columnMapping="Attribute">
   7:                  <dsp:Query QueryType="DSPQ">
   8:                     <dsp:Fields>
   9:                        <dsp:AllFields IncludeHiddenFields="true"/>
  10:                     </dsp:Fields>
  11:                     <dsp:OrderBy>
  12:                        <dsp:OrderField>
  13:                           <Attribute Name="Name">
  14:                              <ClientParameterValue Name="dvt_sortfield"/>
  15:                           </Attribute>
  16:                           <Attribute Name="Direction">
  17:                              <ClientParameterValue Name="dvt_sortdir"/>
  18:                           </Attribute>
  19:                        </dsp:OrderField>
  20:                        <dsp:OrderField Name="Modified" Type="xsd:string" Direction="DESC"/>
  21:                     </dsp:OrderBy>
  22:                     <dsp:Where>
  23:                        <dsp:Or>
  24:                           <dsp:Neq>
  25:                              <dsp:FieldRef Name="Status"/>
  26:                              <dsp:Value Type="x:Text">Finalizada</dsp:Value>
  27:                           </dsp:Neq>
  28:                           <dsp:IsNull>
  29:                              <dsp:FieldRef Name="Status"/>
  30:                           </dsp:IsNull>
  31:                        </dsp:Or>
  32:                     </dsp:Where>
  33:                  </dsp:Query>
  34:               </dsp:dsQuery>
  35:            </dsp:queryRequest>
  36:         </soap:Body>
  37:         <soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  38:            <dsp:versions xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp">
  39:               <dsp:version>1.0</dsp:version>
  40:            </dsp:versions>
  41:            <dsp:request xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" 
		service="DspSts" document="content" method="query">
  42:            </dsp:request>
  43:         </soap:Header>
  44:         <udc:ClientParameterBindings>
  45:            <udc:ClientParameterBinding Name="dvt_sortfield" 
		Location="Postback;Connection" Item="dvt_sortfield"/>
  46:            <udc:ClientParameterBinding Name="dvt_sortdir" 
		Location="Postback;Connection" Item="dvt_sortdir" DefaultValue="Asc"/>
  47:         </udc:ClientParameterBindings>
  48:      </udc:ConnectionInfo>]]>
  49:          </dvwp:DataQuery>

(1) DataQuery - Esta parte encapsula una conexión UDC (2), a través del protocolo SOAP (Simple Object Access Protocol) que es la forma en que los servicios web soportan comunicación RPC sobre XML, mapeado en HTML para facilitar su transporte sobre internet.

La conexión en este caso se realiza mediante el adaptador STSDataAdapter (3) este es un servicio llamado Web Part pages service (WebPartPages.asmx),  el cuerpo del mensaje <soap:body> (4 a 36) contiene la consulta (ver GetXmlDataFromDataSource) (5 a 35), la cabecera <soap:header> (37 a 43) contiene  información adicional acerca del servicio que se va a usar en este caso "DspSts.asmx" (41) que es el servicio de consulta a listas (List Data Retrieval Web Service) y el método en cuestión que es "Query" (41)

(44 a 47) La última parte de este mensaje contiene información acerca de los parámetros que han de pasarse a la conexión estos vienen de <dvwp:ParamBindings> y en este caso, es el campo por el que se va a ordenar los datos de la consulta y el tipo de orden.

   1:   
   2:  <dvwp:XSL>
   3:  <![CDATA[
   4:      <xsl:stylesheet version="1.0" 
   5:                      exclude-result-prefixes="rs z o s ddwrt dt msxsl" 
   6:                      xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
   7:                      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   8:                      xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
   9:                      xmlns:o="urn:schemas-microsoft-com:office" 
  10:                      xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" 
  11:                      xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 
  12:                      xmlns:rs="urn:schemas-microsoft-com:rowset" 
  13:                      xmlns:z="#RowsetSchema">
  

(2) XSL - Está parte del DVWP contiene el XSL que se usará para transformar los datos devueltos por la consulta en HTML. En esta primera parte, se definen los espacios de nombres que intervendrán en la transformación de los datos. El espacio de nombres ddwrt (8), es un módulo que usa SharePoint en tiempo de ejecución para añadir funciones al XSL.

El contenidodel XSL variará mucho en función del diseño que se ha realizado con FrontPage, pero como muestra lo voy a incluir con unas pequeñas descripciones de cada apartado.

El contenido del xsl a su vez está dividido en un apartado de definición de parámetros

   1:         <xsl:param name="PageUrl"/>
   2:         <xsl:param name="HttpHost"/>
   3:         <xsl:param name="HttpPath"/>
   4:         <xsl:param name="List"/>
   5:         <xsl:param name="URL_Display"/>
   6:         <xsl:param name="HttpVDir"/>
   7:         <xsl:param name="View"/>
   8:         <xsl:param name="FilterLink" select="ddwrt:FilterLink()"/>
   9:         <xsl:param name="Language">1033</xsl:param>
  10:         <xsl:param name="dvt_adhocmode">sort</xsl:param>
  11:         <xsl:param name="dvt_adhocfiltermode">xsl</xsl:param>
  12:         <xsl:param name="dvt_fieldsort">1</xsl:param>
  13:         <xsl:param name="dvt_sortfield"></xsl:param>
  14:         <xsl:param name="dvt_groupfield"></xsl:param>
  15:         <xsl:param name="dvt_groupdisplay"></xsl:param>
  16:         <xsl:param name="dvt_sortdir"></xsl:param>
  17:         <xsl:param name="dvt_groupdir"></xsl:param>
  18:         <xsl:param name="dvt_filterfield"></xsl:param>
  19:         <xsl:param name="dvt_filterval"></xsl:param>
  20:         <xsl:param name="dvt_filtertype"></xsl:param>
  21:         <xsl:param name="dvt_firstrow">1</xsl:param>
  22:         <xsl:param name="dvt_p2plinkfields"></xsl:param>
  23:         <xsl:param name="dvt_nextpagedata"></xsl:param>
  24:         <xsl:param name="dvt_grouptype"></xsl:param>
  25:         <xsl:param name="dvt_sorttype"></xsl:param>
  26:         <xsl:param name="dvt_groupsorttype"></xsl:param>
  27:         <xsl:param name="dvt_apos">'</xsl:param>
  28:         <xsl:param name="filterParam" ddwrt:NoCAMLVariable="1"></xsl:param>
  29:         <xsl:param name="ImagesPath"></xsl:param>
  30:         <xsl:param name="ListUrlDir"></xsl:param>
  31:         <xsl:param name="EMail">EMail</xsl:param>
  32:         <xsl:param name="ListUrlDir_TRUE"/>
  33:         <xsl:param name="URL_DISPLAY"/>
  34:         <xsl:param name="URL_EDIT"/>
  35:         <xsl:param name="URL_New"/>
  36:         <xsl:param name="WebQueryInfo"/>
  37:         <xsl:variable name="IDAIHK1H">
		<xsl:choose>
		<xsl:when test="ddwrt:GetVar('ClassInfo')='Menu'">ms-vb-title" height="100%</xsl:when>
		<xsl:when test="ddwrt:GetVar('ClassInfo')='Icon'"></xsl:when>
		<xsl:otherwise>ms-vb2</xsl:otherwise>
	   	</xsl:choose>
	   </xsl:variable>
  38:         <xsl:param name="URL_Edit"/>
  39:         <xsl:param name="URL_Lookup"/>

La plantilla principal

   1:   <xsl:template match="/">
   2:      <xsl:call-template name="dvt_1"/>
   3:   </xsl:template>

Que llama a su vez a la plantilla dvt_1  (Tabla con los resultados)

   1:  <xsl:variable name="StyleName">Table</xsl:variable>
   2:  <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
   3:  <xsl:variable name="FieldNameNoAtSign" select=""/>
   4:  <xsl:variable name="FilteredRowsText" select=""/>
   5:  <xsl:variable name="FilteredRows" select=""/>
   6:  <xsl:variable name="FilteredRowsAttr" select=""/>

Las primeras variables, son las que definimos en las "Propiedades de la vista de datos" en front page, el estilo de la vista, los filtros el ordenar y agrupar etc... El DVWP usa tres variables para los filtros, por texto "FilteredRowsText", por filas "FilteredRows" y por atributos "FilteredRowsAttr".

   1:      <xsl:variable name="RowCount">
   2:          <xsl:choose>
   3:              <xsl:when test="$dvt_adhocfiltermode != 'query' and $dvt_filterfield">
   4:                  <xsl:choose>
   5:                      <xsl:when test="starts-with($dvt_filterfield, '@')">
   6:                          <xsl:value-of select="count($FilteredRowsAttr)"/>
   7:                      </xsl:when>
   8:                      <xsl:when test="$dvt_filterfield = '.'">
   9:                          <xsl:value-of select="count($FilteredRowsText)"/>
  10:                      </xsl:when>
  11:                      <xsl:otherwise>
  12:                          <xsl:value-of select="count($FilteredRows)"/>
  13:                      </xsl:otherwise>
  14:                  </xsl:choose>
  15:              </xsl:when>
  16:              <xsl:otherwise>
  17:                  <xsl:value-of select="count($Rows)"/>
  18:              </xsl:otherwise>
  19:          </xsl:choose>
  20:      </xsl:variable>
  21:      <xsl:variable name="RowLimit" select="20"/>
  22:      <xsl:variable name="IsEmpty" select="$RowCount = 0"/>

Las variables RowCount - número de filas, RowLimit - máximo de filas a mostrar, IsEmpty cuando no hay filas.

   1:  <xsl:choose>
   2:          <xsl:when test="$IsEmpty">
   3:              <TABLE width="100%" cellspacing="0" cellpadding="0" border="0" MsoPnlId="data">
   4:              (Tabla sin resultados)
   5:              </TABLE>
   6:              <xsl:call-template name="dvt_1.toolbar">
   7:                  <xsl:with-param name="Rows" select="$Rows"/>
   8:              </xsl:call-template>
   9:          </xsl:when>

El bloque superior es la tabla que mostrará los datos, primero comprueba si hay datos, en caso de que la consulta no devuelva resultados mostrará una tabla (4) con el mensaje que hemos especificado. (el dvt_1.toolbar lo vemos después). A continuación, si la consulta devuelve resultados, monta un ContextInfo() (ver ows.js) para la tabla de resultados.

   1:  <xsl:otherwise>
   2:  <TABLE width="100%" cellspacing="0" cellpadding="0" border="0" MsoPnlId="data">
   3:      <xsl:text disable-output-escaping="yes">
   4:          &lt;SCRIPT&gt;
   5:          ctx = new ContextInfo();
   6:          ctx.listBaseType =
   7:      </xsl:text>
   8:      <xsl:value-of select="ddwrt:ListProperty('BaseType')"/>;
   9:          ctx.listTemplate = <xsl:value-of select="ddwrt:ListProperty('ServerTemplate')"/>;
  10:          ctx.listName = "<xsl:value-of select="$List"/>";
  11:          ctx.listUrlDir = "<xsl:value-of select="$ListUrlDir_TRUE"/>";
  12:          ctx.HttpPath = "<xsl:value-of select="$HttpPath"/>";
  13:          ctx.HttpRoot = "<xsl:value-of select="$HttpVDir"/>";
  14:          ctx.imagesPath = "/_layouts/images/";
  15:          ctx.PortalUrl = "web";
  16:          if (ctx.PortalUrl == "") ctx.PortalUrl = null;
  17:          ctx.displayFormUrl = "<xsl:value-of select="$URL_DISPLAY"/>";
  18:          ctx.editFormUrl = "<xsl:value-of select="$URL_EDIT"/>";
  19:          ctx.isWebEditorPreview =
  20:          <xsl:choose>
  21:              <xsl:when test="ddwrt:GetVar('WebEditorPreview')='TRUE'">1</xsl:when>
  22:              <xsl:otherwise>0</xsl:otherwise>
  23:          </xsl:choose>;
  24:          ctx.ctxId = 99;
  25:      <xsl:choose>
  26:          <xsl:when test="ddwrt:ListProperty('ModeratedList')='0'"></xsl:when>
  27:          <xsl:otherwise>
  28:          ctx.isModerated = true;
  29:          </xsl:otherwise>
  30:      </xsl:choose>
  31:      <xsl:choose>
  32:          <xsl:when test="ddwrt:GetVar('RecursiveView')='1'">
  33:          ctx.recursiveView = true;
  34:          </xsl:when>
  35:          <xsl:otherwise>
  36:          </xsl:otherwise>
  37:      </xsl:choose>
  38:      ctx99<xsl:text disable-output-escaping="yes"> = ctx;
  39:      &lt;/SCRIPT&gt;
  40:      </xsl:text>

La tabla de resultados

   1:  <TABLE ID="{$List}-{$View}" 
   2:  Summary="{$List}" 
   3:  xmlns:o="urn:schemas-microsoft-com:office:office" 
   4:  o:WebQuerySourceHref="{$HttpPath}&amp;XMLDATA=1&amp;RowLimit=0&amp;View={$View}" 
   5:  width="100%" class="ms-summarystandardbody" 
   6:  border="0" cellspacing="0" cellpadding="1" 
   7:  rules="rows"
   8:  MsoPnlId="data">

Cada cabecera de columna se transforma usando una plantilla para las cabeceras "dvt.headerfield"

   1:  <TH nowrap="" class="ms-vh2">
   2:  <xsl:call-template name="dvt.headerfield" ddwrt:atomic="1">
   3:      <xsl:with-param name="fieldname">@LinkTitleNoMenu</xsl:with-param>
   4:      <xsl:with-param name="fieldtitle">Título</xsl:with-param>
   5:      <xsl:with-param name="sortable">0</xsl:with-param>
   6:      <xsl:with-param name="attachments">0</xsl:with-param>
   7:  </xsl:call-template>
   8:  </TH>

En función del tipo de filtro que este actuando sobre la tabla se llama a la plantilla "dvt_1.body", en cada caso va cambiando el valor "Rows" según el filtro.

   1:  <xsl:when test="$dvt_adhocfiltermode != 'query' and $dvt_filterfield">
   2:      <xsl:choose>
   3:      <xsl:when test="starts-with($dvt_filterfield, '@')">
   4:          <xsl:call-template name="dvt_1.body">
   5:              <xsl:with-param name="Rows" select="$FilteredRowsAttr"/>
   6:              <xsl:with-param name="FirstRow" select="1"/>
   7:              <xsl:with-param name="LastRow" select="$RowLimit"/>
   8:          </xsl:call-template>
   9:      </xsl:when>
  10:      <xsl:when test="$dvt_filterfield = '.'">
  11:          <xsl:call-template name="dvt_1.body">
  12:              <xsl:with-param name="Rows" select="$FilteredRowsText"/>
  13:              <xsl:with-param name="FirstRow" select="1"/>
  14:              <xsl:with-param name="LastRow" select="$RowLimit"/>
  15:          </xsl:call-template>
  16:      </xsl:when>
  17:      <xsl:otherwise>
  18:          <xsl:call-template name="dvt_1.body">
  19:              <xsl:with-param name="Rows" select="$FilteredRows"/>
  20:              <xsl:with-param name="FirstRow" select="1"/>
  21:              <xsl:with-param name="LastRow" select="$RowLimit"/>
  22:          </xsl:call-template>
  23:      </xsl:otherwise>
  24:      </xsl:choose>
  25:  </xsl:when>

Finalmente si a tabla no tiene filtros aplica la plantilla "dvt_1.body"
 

   1:    <xsl:otherwise>
   2:       <xsl:call-template name="dvt_1.body">
   3:          <xsl:with-param name="Rows" select="$Rows" />
   4:          <xsl:with-param name="FirstRow" select="1" />
   5:          <xsl:with-param name="LastRow" select="$RowLimit" />
   6:       </xsl:call-template>
   7:    </xsl:otherwise>
   8:  </xsl:choose>

(fin de la primera parte)

Comments (0)

SharePoint - Funciones del DataViewer webpart

Oct 21 2005 by csegura @ 18:00

Esta mañana modificando una lista en frontpage, me he dado cuenta que si se agrupa por un campo de fecha, el formato de la fecha se queda como MM/DD/AAAA en vez de DD/MM/AAAA, para cambiar el formato siempre se pude recurrir a modificar a mano el xslt del WebPart y cambiar el <xsl:value-of select="ddwrt:GenDisplayName(string(@Created))"/> por <xsl:value-of select="ddwrt:FormatDate(string(@Inicio) ,3082 ,1)"/> y todo arreglado. Las funciones del ddwrt están documentadas gracias a Serge van den Oever, (Macaw) que ya las publico en su blog (SharePoint, Data View web parts and functions in the ddwrt namespace ) y ahora a escrito en el MSDN.

En cualquier caso, una de cal con otra de arena, ya que no se todavía a que se debe pero cuando se agrupa por más de un campo en un xslt, el comportamiento del DataViewer webpart es impredecible, no le he dedicado tiempo aún pero me tiene frito, cuando añado dos agrupaciones la segunda se me queda siempre expandida, y con tres me suceden cosas extrañas. En fin mañana será otro día.

Actualizado:

Cambiar <tr style="display:auto"> por <tr style="display:{$GroupStyle}">
 

Comments (0)

SharePoint - csegSearch Installation Guide

Oct 20 2005 by csegura @ 18:11

1.- Load your search.aspx with http://server/search.aspx&Mode=Edit?PageView=Shared

2.- Enter in design mode using "Modify Shared Page" menu

3.- Select the csegSearch Webpart and put it on page

4.- Go to the original "Search Results" webpart and modify properties, at the end there is a property called ResultListID, it has a list name, remember the name.

5.- Now delete the original "Search Results"

6.- Edit the csegSearch properties and locate the ResultListID, write the same name that the old webpart.

7.- Add your extended rsults and the colorize color.

8.- Apply changes.

Try to search anything...

Comments (0)