﻿<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
  xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
	xmlns:out="urn:barfoo"
	xmlns:outscr="urn:twiddle"
	xmlns:SharePoint="Microsoft.Sharepoint.WebControls"
	exclude-result-prefixes="xsl msxsl"
	version="1.0">
  <xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes" />
  <xsl:preserve-space elements="*"/>
  <xsl:namespace-alias stylesheet-prefix="out" result-prefix="xsl"/>
  <xsl:namespace-alias stylesheet-prefix="outscr" result-prefix="msxsl"/>

  <!-- params designed to be overridden by the caller -->
  <xsl:param name="ID">1</xsl:param>
  <xsl:param name="ViewSpec">
    <View>
      <RowPath>/catalog/book</RowPath>
      <Fields>
        <Field FName="fld_1" FormFieldPrefix="ff2" Value="title" ValueRaw="title" KeyName="keyname" KeyXPath="keyxpath" Title="title" ReadOnly="1" Type="text"/>
        <Field FName="fld_2" FormFieldPrefix="ff3" Value="author" ValueRaw="title" KeyName="keyname" KeyXPath="keyxpath" Title="author" ReadOnly="0" Type="text"/>
        <Field FName="fld_3" FormFieldPrefix="ff4" Value="genre" ValueRaw="title" KeyName="keyname" KeyXPath="keyxpath" Title="genre" ReadOnly="1" Type="text"/>
      </Fields>
    </View>
  </xsl:param>
  <xsl:param name="StyleName">Table</xsl:param>
  <xsl:param name="ShowToolbar">0</xsl:param>
  <xsl:param name="AllowPaging">1</xsl:param>
  <xsl:param name="MaxItemsInPage">1000000</xsl:param>
  <xsl:param name="RowLimit">100</xsl:param>
  <xsl:param name="ShowHeader">0</xsl:param>
  <xsl:param name="ShowFooter">0</xsl:param>
  <xsl:param name="DoXSLJoin">0</xsl:param>

  <!-- all localized text params -->
  <xsl:param name="dvt_ViewEmptyText"></xsl:param>

  <!-- global variables -->
  <xsl:variable name="basename" select="concat('dvt_',$ID)" />
  <xsl:variable name="View" select="msxsl:node-set($ViewSpec)/View" />
  <xsl:variable name="Style" select="/ViewStyles/Style[ID=$StyleName]" />
  <xsl:variable name="Defaults" select="/ViewStyles/Defaults" />

  <xsl:template match="/">
    <out:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
      exclude-result-prefixes="xsl msxsl ddwrt">

      <out:output method="html" indent="no"/>

      <xsl:call-template name="gen-dvt-framework" />

      <out:template match="/">
        <out:call-template name="{$basename}"/>
      </out:template>

      <xsl:apply-templates select="$Style" />
    </out:stylesheet>
  </xsl:template>

  <xsl:template name="gen-dvt-framework">
    <!-- BEGIN: params set by runtime -->
    <out:param name="PreviousLinkText">Previous</out:param>
    <out:param name="NextLinkText">Next</out:param>
    <out:param name="EditViewText">Edit View</out:param>
    <out:param name="AscendingText">Ascending</out:param>
    <out:param name="DescendingText">Descending</out:param>
    <out:param name="RetrieveDataText">Retrieve Data</out:param>
    <out:param name="ActionsText">Actions</out:param>
    <out:param name="FilterNameText">Filter name</out:param>
    <out:param name="OperatorText">Operator</out:param>
    <out:param name="AddText">Add</out:param>
    <out:param name="CurrentLCID">1033</out:param>
    <out:param name="OpenMenuToolTip">Open Menu</out:param>
    <out:param name="DataTableSummary">Entity Summary</out:param>
    <out:param name="SelectionRadioButtonToolTip">Pick Item</out:param>
    <out:param name="DownloadStreamText">Click here to download</out:param>
    <out:param name="IsRTL"/>

    <out:param name="dvt_apos">&#x27;</out:param>
    <out:param name="dvt_adhocmode">sort</out:param>
    <out:param name="ClickThroughUrl"></out:param>
    <out:param name="DownloadExternalDataUrl"></out:param>
    <out:param name="dvt_url"></out:param>

    <!-- these are already EcmaScript encoded -->
    <out:param name="jsMenuApplication"></out:param>
    <out:param name="jsMenuEntityNamespace"></out:param>
    <out:param name="jsMenuEntityName"></out:param>
    <out:param name="jsMenuLoadingMessage"></out:param>

    <!-- automode variable, managed by DVT manager -->
    <out:param name="{$basename}_automode">0</out:param>

    <!-- o11 #327468: always add a sample param -->
    <out:param name="filterParam"></out:param>
    <out:param name="dvt_firstrow">1</out:param>
    <out:param name="dvt_nextpagedata"/>
    <out:param name="IsMenuVisible"/>
    <out:param name="IsEditViewVisible"/>
    <out:param name="dvt_partguid"/>
    <out:param name="ColumnKey">Kunnr</out:param>
    <out:param>
      <xsl:attribute name="name"><xsl:value-of select="$basename"/>_form_selectkey</xsl:attribute>
    </out:param>

    <out:param name="dvt_sortdir">ascending</out:param>
    <out:param name="dvt_sortfield" />
    <out:param name="dvt_emptytext">
      <xsl:value-of select="$dvt_ViewEmptyText"/>
    </out:param>
    <out:param name="dvt_filterfields"/>

    <xsl:for-each select="$View/Fields/Field">
      <out:param name="{@Title}">
        <xsl:value-of select="$View/Fields/Field/Title"/>
      </out:param>
    </xsl:for-each>
    <!-- END: params set by runtime -->

    <!-- generic template to display a header field -->
    <xsl:if test="$StyleName='Table'">
      <out:template name="dvt.headerfield">
        <out:param name="fieldname"/>
        <out:param name="fieldtitle"/>
        <out:param name="displayname"/>
        <out:param name="fieldtype">0</out:param>

        <out:variable name="sortfield">
          <out:choose>
            <out:when test="substring($fieldname, 1, 1) = '@'">
              <out:value-of select="substring($fieldname, 2)"/>
            </out:when>
            <out:otherwise>
              <out:value-of select="$fieldname"/>
            </out:otherwise>
          </out:choose>
        </out:variable>
        <out:variable name="linkdir">
          <out:choose>
            <out:when test="$dvt_sortfield = $sortfield and $dvt_sortdir = 'ascending'">descending</out:when>
            <out:otherwise>ascending</out:otherwise>
          </out:choose>
        </out:variable>
        <out:variable name="sortText">
          <out:choose>
            <out:when test="$linkdir='descending'">' + 'descending' + '</out:when>
            <out:otherwise>' + 'ascending' + '</out:otherwise>
          </out:choose>
        </out:variable>

        <out:variable name="separator" select="' '"/>
        <out:variable name="connector" select="';'"/>
        <out:variable name="filterString" select="concat($displayname,$separator,$fieldname,$separator,$fieldtype,$connector,$CurrentLCID,$separator,$dvt_partguid)" />

        <table CtxNum="1" cellspacing="0" class="ms-unselectedtitle">
          <out:if test="$fieldname">
            <out:attribute name="onmouseover">OnMouseOverAdHocFilter(this, '<out:value-of select="$filterString"/>')</out:attribute>
          </out:if>
          <tr>
            <td width="100%" class="ms-vb" nowrap="">
              <out:choose>
                <out:when test="$fieldname">
                  <a>
                    <out:attribute name="href">javascript: <out:value-of select="ddwrt:GenFireServerEvent(concat('dvt_sortfield={{',$sortfield,'}};dvt_sortdir={{',$sortText,'}}'))" />;</out:attribute>
                    <out:value-of select="$fieldtitle"/>
                    <out:if test="$dvt_sortfield = $sortfield">
                      <out:choose>
                        <out:when test="$dvt_sortdir = 'ascending'">
                          <img border="0" alt="{{$AscendingText}}" src="{{ddwrt:FieldSortImageUrl('Desc')}}" />
                        </out:when>
                        <out:when test="$dvt_sortdir = 'descending'">
                          <img border="0" alt="{{$DescendingText}}" src="{{ddwrt:FieldSortImageUrl('Asc')}}" />
                        </out:when>
                      </out:choose>
                    </out:if>
                  </a>
                  <out:if test="contains($dvt_filterfields, concat($fieldname, ';' ))">
                    <img src="/_layouts/images/filter.gif" border="0" alt=""/>
                  </out:if>
                </out:when>
                <out:otherwise>
                  <out:value-of select="$fieldtitle" />
                </out:otherwise>
              </out:choose>
            </td>
            <td><img src="/_layouts/images/blank.gif" width="13" style="visibility: hidden" alt=""/></td>
          </tr>
        </table>
      </out:template>
    </xsl:if>
  </xsl:template>

  <xsl:template match="Style">
    <!-- output all the templates -->
    <xsl:apply-templates select="Main"/>
    <xsl:call-template name="GenHeader"/>
    <xsl:apply-templates select="Body"/>

    <xsl:if test="$StyleName='Table'">
      <xsl:call-template name="GenToolbar"/>
      <xsl:call-template name="GenNavigation"/>
      <xsl:call-template name="GenCommandHeader"/>
      <xsl:call-template name="AutoMode"/>
    </xsl:if>

    <xsl:call-template name="GenerateFormatString"/>
    <xsl:call-template name="GenerateOpenActionsMenuScriptCall"/>
    <xsl:call-template name="GenerateLFtoBR"/>
  </xsl:template>

  <xsl:template name="gen-field-view">
    <xsl:param name="ThisField"/>

    <xsl:variable name="fieldValue">
      <xsl:choose>
        <xsl:when test="$ThisField/@IsStreamableField">
          <a>
            <out:variable name="downloadUrl" select="concat($DownloadExternalDataUrl, ddwrt:UrlEncode('{$ThisField/@StreamAccessorName}'), '&amp;IsXmlEncodedStreamName=true&amp;ItemId=', @*[name()=$ColumnKey])"/>
            <out:attribute name="href">
              <out:value-of select="$downloadUrl"/>
            </out:attribute>
            <out:attribute name="onclick">javascript: DownloadExternalData('<xsl:value-of select="$ThisField/@StreamAccessorName" />', '<out:value-of select="@*[name()=$ColumnKey]" />', '<out:value-of select="concat($downloadUrl, '&amp;InvisibleFrame=true')"/>'); return false;</out:attribute>
            <out:value-of select="$DownloadStreamText"/>
          </a>
          <!-- Add the invisible iFrame to invoke the download url in case user clicks the link-->
          <span style="display:none">
            <iframe>
              <!-- Give it a unique name so we can find it at runtime -->
              <out:attribute name="name">
                <out:value-of select="concat('{$ThisField/@StreamAccessorName}', @*[name()=$ColumnKey], 'DownloadFrame')" />
              </out:attribute>
            </iframe>
          </span>
        </xsl:when>
        <xsl:when test="$ThisField/@Type = 'text'">
          <out:variable name="fieldValue">
            <out:call-template name="LFtoBR">
              <out:with-param name="input">
                <out:value-of select="{$ThisField/@Value}"/>
              </out:with-param>
            </out:call-template>
          </out:variable>
          <out:copy-of select="$fieldValue"/>
        </xsl:when>
        <xsl:when test="$ThisField/@Type = 'datetime'">
          <out:value-of select="ddwrt:FormatDateTimeUsingCurrentContext(string({$ThisField/@Value}))"/>
       </xsl:when>
        <xsl:otherwise>
          <out:value-of select="{$ThisField/@Value}"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:choose>
      <xsl:when test="not($ThisField/@HasMenu)">
        <xsl:copy-of select="$fieldValue"/>
      </xsl:when>
      <xsl:otherwise>
        <out:variable name="output">
          <out:variable name="rowId" select="@*[name()=$ColumnKey]"/>
          <out:choose>
            <out:when test="$IsMenuVisible">
              <div class="ms-vb-title">
                <table height="100%" cellspacing="0" class="ms-unselectedtitle"  onmouseover="MMU_EcbTableMouseOverOut(this, true)" hoverActive="ms-selectedtitle" hoverInactive="ms-unselectedtitle"  oncontextmenu="this.click(); return false;" menuformat="ArrowOnHover">
                  <out:attribute name="downArrowTitle">
                    <out:value-of select="$OpenMenuToolTip"/>
                  </out:attribute>
                  <out:attribute name="id">
                    <out:value-of select="$rowId"/><out:text>t</out:text>
                  </out:attribute>
                  <out:attribute name="onclick">
                    <out:call-template name="OpenActionsMenu">
                      <out:with-param name="method">showActionMenu</out:with-param>
                      <out:with-param name="id" select="$rowId"/>
                      <out:with-param name="menuText"><xsl:copy-of select="$fieldValue"/></out:with-param>
                    </out:call-template>
                  </out:attribute>
                  <tr>
                    <td class="ms-vb">
                      <a onclick="event.cancelBubble=true">
                        <out:if test="$ClickThroughUrl">
                          <out:attribute name="href">
                            <out:value-of select="concat($ClickThroughUrl, $rowId)"/>
                          </out:attribute>
                        </out:if>
                        <out:attribute name="onkeydown">
                          <out:call-template name="OpenActionsMenu">
                            <out:with-param name="method">actionMenuOnKeyDown</out:with-param>
                            <out:with-param name="id" select="$rowId"/>
                            <out:with-param name="menuText"><xsl:copy-of select="$fieldValue"/></out:with-param>
                          </out:call-template>
                        </out:attribute>
                        <xsl:copy-of select="$fieldValue"/>
                        <img src="/_layouts/images/blank.gif" border="0" alt=""/>
                      </a>
                    </td>
                    <td class="ms-menuimagecell" style="visibility:hidden">
                      <out:attribute name="id">
                        <out:value-of select="$rowId"/><out:text>ti</out:text>
                      </out:attribute>
                      <img src="/_layouts/images/downarrw.gif" width="13" >
                        <out:attribute name="alt">
                          <out:value-of select="$OpenMenuToolTip"/>
                        </out:attribute>
                        <out:attribute name="title">
                          <out:value-of select="$OpenMenuToolTip"/>
                        </out:attribute>
                      </img>
                    </td>
                  </tr>
                </table>
              </div>
              <!-- the ECB menu will be inserted into this span -->
              <span></span>
            </out:when>
            <out:otherwise>
              <xsl:copy-of select="$fieldValue"/>
            </out:otherwise>
          </out:choose>
        </out:variable>
        <out:copy-of select="$output"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="gen-param">
    <out:param name="{@Name}">
      <xsl:value-of select="@Default"/>
    </out:param>
  </xsl:template>

  <xsl:template match="Main">
    <!-- this is the root template for the DVT -->
    <out:template name="{$basename}">
      <xsl:for-each select="$Style/Params/Param">
        <xsl:call-template name="gen-param" />
      </xsl:for-each>
      <out:variable name="dvt_StyleName">
        <xsl:value-of select="$StyleName" />
      </out:variable>
      <xsl:if test="$DoXSLJoin = '1'">
        <out:variable name="dvt_ParentRow">
          <xsl:attribute name="select">current()</xsl:attribute>
        </out:variable>
      </xsl:if>
      <out:variable name="Rows" select="{$View/RowPath}" />
      <out:variable name="dvt_RowCount" select="count($Rows)" />
      <out:variable name="RowLimit">
        <xsl:attribute name="select">
          <xsl:choose>
            <xsl:when test="$AllowPaging = '1'">
              <xsl:value-of select="$MaxItemsInPage"/>
            </xsl:when>
            <xsl:otherwise>$dvt_RowCount</xsl:otherwise>
          </xsl:choose>
        </xsl:attribute>
      </out:variable>
      <out:variable name="FirstRow" select="$dvt_firstrow" />
      <out:variable name="LastRow">
        <out:choose>
          <out:when test="($FirstRow + $RowLimit - 1) &gt; $dvt_RowCount">
            <out:value-of select="$dvt_RowCount" />
          </out:when>
          <out:otherwise>
            <out:value-of select="$FirstRow + $RowLimit - 1" />
          </out:otherwise>
        </out:choose>
      </out:variable>

      <xsl:if test="$ShowToolbar = '1'">
        <out:call-template name="{$basename}.toolbar">
          <out:with-param name="Rows" select="$Rows" />
        </out:call-template>
      </xsl:if>

      <xsl:apply-templates />

    </out:template>
  </xsl:template>

  <xsl:template match="Header">
    <out:template name="{$basename}.header">
      <out:param name="Rows"/>
      <xsl:apply-templates />
    </out:template>
  </xsl:template>

  <xsl:template match="Body">
    <out:template name="{$basename}.body">
      <out:param name="Rows"/>
      <out:param name="FirstRow" />
      <out:param name="LastRow" />

      <xsl:if test="$DoXSLJoin = '1'">
        <out:param name="dvt_ParentRow"/>
      </xsl:if>

      <out:for-each select="$Rows">
        <xsl:choose>
          <xsl:when test="not($AllowPaging = '1')">
            <out:call-template name="{$basename}.rowview"/>
          </xsl:when>
          <xsl:otherwise>
            <out:if test="position() &gt;= $FirstRow and position() &lt;= $LastRow">
              <out:call-template name="{$basename}.rowview"/>
            </out:if>
          </xsl:otherwise>
        </xsl:choose>
      </out:for-each>
    </out:template>

    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="RowView">
    <out:template name="{$basename}.rowview">
      <xsl:apply-templates/>
    </out:template>
  </xsl:template>

  <xsl:template match="Navigation">
    <out:template name="{$basename}.navigation">
      <out:param name="FirstRow"/>
      <out:param name="LastRow"/>
      <out:param name="RowLimit"/>
      <out:param name="dvt_RowCount"/>

      <out:variable name="PrevRow">
        <out:choose>
          <out:when test="$FirstRow - $RowLimit &lt; 1">1</out:when>
          <out:otherwise>
            <out:value-of select="$FirstRow - $RowLimit"/>
          </out:otherwise>
        </out:choose>
      </out:variable>
      <xsl:apply-templates/>
    </out:template>
  </xsl:template>

  <xsl:template match="CommandHeader">
    <out:template name="{$basename}.commandheader">
      <out:param name="FirstRow"/>
      <out:param name="LastRow"/>
      <out:param name="RowLimit"/>
      <out:param name="dvt_RowCount"/>

      <xsl:apply-templates/>
    </out:template>
  </xsl:template>

  <xsl:template match="Toolbar">
    <out:template name="{$basename}.toolbar">
      <out:param name="Rows" />
      <xsl:apply-templates />
    </out:template>
  </xsl:template>


  <!-- templates to generate default parts of views -->
  <xsl:template name="GenEmpty">
    <xsl:choose>
      <xsl:when test="Empty">
        <xsl:apply-templates select="Empty" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="msxsl:node-set($Defaults)/Empty" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="GenHeader">
    <xsl:choose>
      <xsl:when test="Header">
        <xsl:apply-templates select="Header" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="msxsl:node-set($Defaults)/Header" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="GenFooter">
    <xsl:choose>
      <xsl:when test="Footer">
        <xsl:apply-templates select="Footer" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="msxsl:node-set($Defaults)/Footer" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="GenSummary">
    <xsl:choose>
      <xsl:when test="Summary">
        <xsl:apply-templates select="Summary" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="msxsl:node-set($Defaults)/Summary" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="GenToolbar">
    <xsl:choose>
      <xsl:when test="Toolbar">
        <xsl:apply-templates select="Toolbar" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="msxsl:node-set($Defaults)/Toolbar" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="AutoMode">
    <out:template name="{$basename}.automode">
      <out:param name="KeyField"/>
      <out:param name="KeyValue"/>
      <out:param name="Mode"/>

      <xsl:choose>
        <xsl:when test="text() = 'vertical'">
          <xsl:apply-templates select="msxsl:node-set($Defaults)/AutoModeVertical/*"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="msxsl:node-set($Defaults)/AutoModeHorizontal/*"/>
        </xsl:otherwise>
      </xsl:choose>
    </out:template>
  </xsl:template>

  <xsl:template name="GenCommandHeader">
    <xsl:choose>
      <xsl:when test="CommandHeader">
        <xsl:apply-templates select="CommandHeader" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="msxsl:node-set($Defaults)/CommandHeader" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="GenNavigation">
    <xsl:choose>
      <xsl:when test="Navigation">
        <xsl:apply-templates select="Navigation" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="msxsl:node-set($Defaults)/Navigation" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- implement the known tags in the "dvt" namespace -->

  <!-- this tag only works in Navigation template -->
  <xsl:template match="dvt_PrevLink">
    <!-- DSP paging does not support previous; use browser history link instead -->
    <!-- if we are doing xsl paging, then we can simply pass the firstrow value -->
    <a>
      <out:attribute name="href">
        <xsl:choose>
          <xsl:when test="not($AllowPaging = '1')">javascript: history.back();</xsl:when>
          <xsl:otherwise>javascript: <out:value-of select="ddwrt:GenFireServerEvent(concat('dvt_firstrow={{',$PrevRow,'}}'))" />;</xsl:otherwise>
        </xsl:choose>
      </out:attribute>
      <img src="{{ddwrt:PagingImageUrl('Previous')}}" border="0" alt="{{$PreviousLinkText}}"/>
    </a>
  </xsl:template>

  <!-- this tag only works in Navigation template -->
  <xsl:template match="dvt_NextLink">
    <!-- if we are doing DSP paging, then we have to pass the dvt_nextpagedata back as the StartPosition -->
    <!-- if we are doing xsl paging, then we can simply pass the firstrow value -->
    <a>
      <out:attribute name="href">
        <xsl:choose>
          <xsl:when test="not($AllowPaging = '1')">javascript: <out:value-of select="ddwrt:GenFireServerEvent(concat('dvt_firstrow={{',$NextRow,'}};StartPosition={{',$dvt_nextpagedata,'}}'))" />;</xsl:when>
          <xsl:otherwise>javascript: <out:value-of select="ddwrt:GenFireServerEvent(concat('dvt_firstrow={{',$NextRow,'}}'))" />;</xsl:otherwise>
        </xsl:choose>
      </out:attribute>
      <img src="{{ddwrt:PagingImageUrl('Next')}}" border="0" alt="{{$NextLinkText}}"/>
    </a>
  </xsl:template>

  <!-- this tag only works in Navigation template -->
  <xsl:template match="dvt_IfNotFirstPage">
    <out:if test="$dvt_firstrow > 1" ddwrt:cf_ignore="1">
      <xsl:apply-templates/>
    </out:if>
  </xsl:template>

  <xsl:template match="dvt_Header">
    <xsl:if test="$ShowHeader = '1'">
      <out:call-template name="{$basename}.header" >
        <out:with-param name="Rows" select="$Rows"/>
      </out:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template match="dvt_TableSummary">
    <out:attribute name="summary">
      <out:value-of select="$DataTableSummary"/>
    </out:attribute>
  </xsl:template>

  <xsl:template match="dvt_Body">
    <out:call-template name="{$basename}.body">
      <out:with-param name="Rows" select="$Rows"/>
      <out:with-param name="FirstRow" select="$dvt_firstrow" />
      <out:with-param name="LastRow" select="$LastRow" />

      <xsl:if test="$DoXSLJoin = '1'">
        <out:with-param name="dvt_ParentRow" select="$dvt_ParentRow"/>
      </xsl:if>
    </out:call-template>
  </xsl:template>

  <xsl:template match="dvt_Footer">
    <xsl:if test="$ShowFooter = '1'">
      <out:call-template name="{$basename}.footer">
        <out:with-param name="Rows" select="$Rows"/>
      </out:call-template>
    </xsl:if>
  </xsl:template>

  <!-- designed to be called from within the commandheader template -->
  <xsl:template match="dvt_Navigation">
    <out:call-template name="{$basename}.navigation">
      <out:with-param name="FirstRow" select="$FirstRow"/>
      <out:with-param name="LastRow" select="$LastRow"/>
      <out:with-param name="RowLimit" select="$RowLimit"/>
      <out:with-param name="dvt_RowCount" select="$dvt_RowCount"/>
    </out:call-template>
  </xsl:template>

  <xsl:template match="dvt_FieldView">
    <xsl:param name="ThisField"/>

    <xsl:call-template name="gen-field-view">
      <xsl:with-param name="ThisField" select="$ThisField"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="dvt_FieldTitle[@Name]">
    <xsl:variable name="ThisField" select="$View/Fields/Field[@FName=current()/@Name]"/>
    <xsl:value-of select="$ThisField/@Title" />
  </xsl:template>

  <xsl:template match="dvt_FieldTitle">
    <xsl:param name="ThisField"/>

    <xsl:choose>
      <xsl:when test="$StyleName='Table'">
        <out:call-template name="dvt.headerfield" ddwrt:atomic="1">
          <out:with-param name="fieldname">
            <xsl:value-of select="$ThisField/@Value" />
          </out:with-param>
          <out:with-param name="fieldtitle">
            <out:value-of select="{concat('$', $ThisField/@Title)}" />
          </out:with-param>
          <out:with-param name="displayname">
            <out:value-of select="{concat('$', $ThisField/@Title)}"/>
          </out:with-param>
          <out:with-param name="fieldtype">
            <xsl:value-of select="$ThisField/@Type"/>
          </out:with-param>
        </out:call-template>
      </xsl:when>
      <xsl:otherwise>
        <out:value-of select="${$ThisField/@Title}" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="dvt_FieldHeader[@Name]">
    <xsl:variable name="ThisField" select="$View/Fields/Field[@FName=current()/@Name]"/>
    <out:variable name="{$ThisField/@FName}">
      <out:call-template name="dvt.headerfield">
        <out:with-param name="fieldname">
          <xsl:value-of select="$ThisField/@Value"/>
        </out:with-param>
        <out:with-param name="fieldtitle">
          <xsl:value-of select="$ThisField/@Title"/>
        </out:with-param>
        <out:with-param name="displayname">
          <xsl:value-of select="$ThisField/@Title"/>
        </out:with-param>
        <out:with-param name="fieldtype">
          <xsl:value-of select="$ThisField/@Type"/>
        </out:with-param>
      </out:call-template>
    </out:variable>
    <out:copy-of select="${$ThisField/@FName}" />
  </xsl:template>

  <xsl:template match="dvt_FieldHeader">
    <xsl:param name="ThisField"/>
    <out:variable name="{$ThisField/@FName}">
      <out:call-template name="dvt.headerfield">
        <out:with-param name="fieldname">
          <xsl:value-of select="$ThisField/@Value"/>
        </out:with-param>
        <out:with-param name="fieldtitle">
          <xsl:value-of select="$ThisField/@Title"/>
        </out:with-param>
        <out:with-param name="displayname">
          <xsl:value-of select="$ThisField/@Title"/>
        </out:with-param>
        <out:with-param name="fieldtype">
          <xsl:value-of select="$ThisField/@Type"/>
        </out:with-param>
      </out:call-template>
    </out:variable>
    <out:copy-of select="${$ThisField/@FName}" />
  </xsl:template>

  <xsl:template match="dvt_FieldFilter">
    <xsl:param name="ThisField"/>

    <out:call-template name="dvt.filterfield">
      <out:with-param name="fieldname">
        <!-- Remove synthetized ddw prefixes used for default namespaces when calling into the dvt.filterfield template. -->
        <xsl:choose>
          <xsl:when test="contains($ThisField/@Value, ':') and starts-with($ThisField/@Value, 'ddw')">
            <xsl:value-of select="substring-after($ThisField/@Value, ':')"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$ThisField/@Value"/>
          </xsl:otherwise>
        </xsl:choose>
      </out:with-param>
      <out:with-param name="fieldtitle">
        <!-- Remove synthetized ddw prefixes used for default namespaces when calling into the dvt.filterfield template. -->
        <xsl:choose>
          <xsl:when test="contains($ThisField/@Title, ':') and starts-with($ThisField/@Title, 'ddw')">
            <xsl:value-of select="substring-after($ThisField/@Title, ':')"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$ThisField/@Title"/>
          </xsl:otherwise>
        </xsl:choose>
      </out:with-param>
      <out:with-param name="Rows" select="$Rows"/>
      <out:with-param name="fieldtype">
        <xsl:value-of select="$ThisField/@Type"/>
      </out:with-param>
    </out:call-template>
  </xsl:template>

  <xsl:template match="dvt_FieldFilter[@Name]">
    <xsl:variable name="ThisField" select="$View/Fields/Field[@FName=current()/@Name]"/>

    <out:call-template name="dvt.filterfield">
      <out:with-param name="fieldname">
        <xsl:value-of select="$ThisField/@Value"/>
      </out:with-param>
      <out:with-param name="fieldtitle">
        <xsl:value-of select="$ThisField/@Title"/>
      </out:with-param>
      <out:with-param name="Rows" select="$Rows"/>
      <out:with-param name="fieldtype">
        <xsl:value-of select="$ThisField/@Type"/>
      </out:with-param>
    </out:call-template>
  </xsl:template>

  <xsl:template match="dvt_CommandHeader">
    <out:call-template name="{$basename}.commandheader">
      <out:with-param name="FirstRow" select="$FirstRow" />
      <out:with-param name="LastRow" select="$LastRow" />
      <out:with-param name="RowLimit" select="$RowLimit" />
      <out:with-param name="dvt_RowCount" select="$dvt_RowCount" />
    </out:call-template>
  </xsl:template>

  <xsl:template match="dvt_ListActionBar">
    <asp:PlaceHolder id="ActionBarTable" runat="server">
      <table class="ms-menutoolbar" cellpadding="2" cellspacing="0" border="0" width="100%">
        <tr>
          <td class="ms-toolbar" style="padding-left:3px;text-align:left" nowrap="true"><out:value-of select="$ActionsText"/></td>
          <td class="ms-toolbar" style="padding-right:3px;text-align:right" nowrap="true"><out:value-of select="$EditViewText"/></td>
        </tr>
      </table>
    </asp:PlaceHolder>
  </xsl:template>

  <xsl:template match="dvt_ItemActionBar">
    <asp:PlaceHolder id="ActionBarTable" runat="server">
      <table class="ms-toolbar" cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr style="height:2em">
          <td valign="middle" style="padding-left:2px">
            <img src="/_layouts/{{$CurrentLCID}}/images/viewprof.gif" border="0" alt=""/>
          </td>
          <td valight="middle" style="padding-left:2px; width:100%;">
            <a href="#">View Profile</a>
          </td>
        </tr>
      </table>
    </asp:PlaceHolder>
  </xsl:template>

  <xsl:template match="dvt_SearchTable">
    <asp:PlaceHolder id="SearchTable" runat="server">
      <table width="100%" style="background-color:#efefd6">
        <tr class="ms-vb">
          <td><select><option><out:value-of select="$FilterNameText"/></option></select></td>
          <td><select><option><out:value-of select="$OperatorText"/></option></select></td>
          <td width="100%" nowrap="true"><input class="ms-input" style="width:100%"/></td>
          <td valign="middle"><a href="#"><out:value-of select="$AddText"/></a></td>
        </tr>
      </table>
      <table width="100%" style="background-color:#efefd6">
        <tr>
          <td style="width:16pt;" valign="middle">
            <out:choose>
              <out:when test="$IsRTL"><img src="/_layouts/images/icongo01RTL.gif" border="0"/></out:when>
              <out:otherwise><img src="/_layouts/images/icongo01.gif" border="0"/></out:otherwise>
            </out:choose>
          </td>
          <td class="ms-vb" valign="middle"><a href="#"><out:value-of select="$RetrieveDataText"/></a></td>
        </tr>
      </table>
    </asp:PlaceHolder>
  </xsl:template>

  <xsl:template match="dvt_ForEachField">
    <xsl:variable name="CurNode" select="."/>
    <xsl:variable name="ReqFields">
      <xsl:if test="@ExcludeRequired">
        <xsl:for-each select="$Style/RequiredFields/Field">
          <xsl:text> </xsl:text>
          <xsl:value-of select="@Name"/>
          <xsl:text> </xsl:text>
        </xsl:for-each>
      </xsl:if>
    </xsl:variable>
    <xsl:for-each select="$View/Fields/Field[not(@Hidden) and not(contains($ReqFields,concat(' ',@FName,' ')))]">
      <xsl:variable name="ThisField" select="."/>
      <xsl:variable name="FieldNum" select="position()"/>
      <xsl:apply-templates select="$CurNode/node()">
        <xsl:with-param name="ThisField" select="$ThisField"/>
        <xsl:with-param name="FieldNum" select="$FieldNum"/>
      </xsl:apply-templates>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="dvt_ForEachRow">
    <out:for-each select="{$View/RowPath}">
      <xsl:apply-templates select="node()"/>
    </out:for-each>
  </xsl:template>

  <xsl:template match="dvt_IfNotEmpty">
    <out:if test="count({$View/RowPath})!=0">
      <xsl:apply-templates/>
    </out:if>
  </xsl:template>

  <xsl:template match="dvt_IfEmpty">
    <out:if test="count({$View/RowPath})=0">
      <xsl:apply-templates/>
    </out:if>
  </xsl:template>

  <xsl:template match="dvt_IfNewGroup">
    <xsl:if test="$View/Sorting[@Grouping='TRUE']">
      <out:if test="$NewGroup = 'TRUE'" ddwrt:cf_ignore="1">
        <xsl:apply-templates>
          <xsl:with-param name="ThisField" select="$View/Fields/Field[@FName=$View/Sorting/SortBy[1]/@Field]"/>
        </xsl:apply-templates>
      </out:if>
    </xsl:if>
  </xsl:template>

  <xsl:template match="dvt_IfEvenRow">
    <out:if test="position() mod 2 = 0" ddwrt:cf_ignore="1">
      <xsl:apply-templates/>
    </out:if>
  </xsl:template>

  <xsl:template match="dvt_IfOddRow">
    <out:if test="position() mod 2 != 0" ddwrt:cf_ignore="1">
      <xsl:apply-templates/>
    </out:if>
  </xsl:template>

  <xsl:template match="dvt_IfFirstRow">
    <out:if test="position() = 1" ddwrt:cf_ignore="1">
      <xsl:apply-templates/>
    </out:if>
  </xsl:template>

  <xsl:template match="dvt_IfLastRow">
    <out:if test="position() = last()" ddwrt:cf_ignore="1">
      <xsl:apply-templates/>
    </out:if>
  </xsl:template>

  <xsl:template match="dvt_IfNotFirstRow">
    <out:if test="position() != 1" ddwrt:cf_ignore="1">
      <xsl:apply-templates/>
    </out:if>
  </xsl:template>

  <xsl:template match="dvt_IfNotLastRow">
    <out:if test="position() != last()" ddwrt:cf_ignore="1">
      <xsl:apply-templates/>
    </out:if>
  </xsl:template>

  <xsl:template match="dvt_IfFirstField">
    <xsl:param name="FieldNum"/>
    <xsl:if test="$FieldNum = 1">
      <xsl:apply-templates/>
    </xsl:if>
  </xsl:template>

  <xsl:template match="dvt_IfNotFirstField">
    <xsl:param name="FieldNum"/>
    <xsl:if test="$FieldNum != 1">
      <xsl:apply-templates/>
    </xsl:if>
  </xsl:template>

  <xsl:template match="dvt_IfVarEq">
    <out:if test="${@name} = '{@value}'" ddwrt:cf_ignore="1">
      <xsl:apply-templates/>
    </out:if>
  </xsl:template>

  <xsl:template match="dvt_HTML">
    <out:text disable-output-escaping="yes">
      <xsl:apply-templates/>
    </out:text>
  </xsl:template>

  <xsl:template match="dvt_NBSP">
    <out:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</out:text>
  </xsl:template>

  <xsl:template match="dvt_Comment">
    <out:comment>
      <xsl:apply-templates/>
    </out:comment>
  </xsl:template>

  <xsl:template match="dvt_GetVar">
    <out:value-of select="${@Name}"/>
  </xsl:template>

  <xsl:template match="dvt_ShowVar">
    <out:value-of select="{@Name}"/>
  </xsl:template>

  <xsl:template match="dvt_DisplayVar">
    <out:value-of select="${@Name}" disable-output-escaping="yes"/>
  </xsl:template>

  <xsl:template match="dvt_PageItemText">
    <out:value-of select="$FirstRow"/> - <out:value-of select="$LastRow"/>
  </xsl:template>

  <xsl:template match="dvt_EmptyText">
    <out:value-of select="$dvt_emptytext"/>
  </xsl:template>

  <!--xsl:template match="dvt_ErrorText">
    <xsl:if test="$dvt_errortext">
      <out:value-of select="$dvt_errortext"/>
    </xsl:if>
  </xsl:template-->

  <xsl:template match="dvt_EditView">
    <out:value-of select="$EditViewText"/>
  </xsl:template>

  <xsl:template match="dvt_FullText">
    <!--out:value-of select="$FirstRow"/> - <out:value-of select="$LastRow"/-->
  </xsl:template>

  <xsl:template match="*">
    <xsl:param name="ThisField"/>
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates>
        <xsl:with-param name="ThisField" select="$ThisField"/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="dvt_AutoMode">
    <xsl:variable name="KeyFieldSelect">
      <xsl:choose>
        <!-- if there is a field with a KeyName -->
        <xsl:when test="count($View/Fields/Field[string-length(@KeyName) != 0]) > 0">
          <xsl:value-of select="$View/Fields/Field[string-length(@KeyName) != 0]/@KeyName"/>
        </xsl:when>
        <xsl:otherwise></xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <out:choose>
      <out:when test="${$basename}_automode = '1'">
        <out:call-template name="{$basename}.automode">
          <out:with-param name="KeyField">
            <xsl:value-of select="$KeyFieldSelect"/>
          </out:with-param>
          <out:with-param name="KeyValue">
            <xsl:attribute name="select">@*[name()=$ColumnKey]</xsl:attribute>
          </out:with-param>
          <out:with-param name="Mode">
            <xsl:value-of select="@mode"/>
          </out:with-param>
        </out:call-template>
      </out:when>
      <out:otherwise>
        <xsl:variable name="KeyValueSelect">
          <xsl:choose>
            <!-- if there is a field with a KeyXPath -->
            <xsl:when test="count($View/Fields/Field[string-length(@KeyXPath) != 0]) > 0">
              <xsl:value-of select="$View/Fields/Field[string-length(@KeyXPath) != 0]/@KeyXPath"/>
            </xsl:when>
            <xsl:otherwise>''</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>

        <!-- put the values needed to make the automode template call in attributes of a span tag -->
        <span ddwrt:amkeyfield="{$KeyFieldSelect}" ddwrt:amkeyvalue="{$KeyValueSelect}" ddwrt:ammode="{@mode}"></span>
      </out:otherwise>
    </out:choose>
  </xsl:template>

  <xsl:template match="dvt_WhenAutoModeEdit">
    <out:when test="$Mode = 'edit'">
      <xsl:apply-templates/>
    </out:when>
  </xsl:template>

  <xsl:template match="dvt_WhenAutoModeInsert">
    <out:when test="$Mode = 'insert'">
      <xsl:apply-templates/>
    </out:when>
  </xsl:template>

  <xsl:template match="dvt_InsertLink">
  </xsl:template>

  <xsl:template match="dvt_SaveEditLink">
  </xsl:template>

  <xsl:template match="dvt_SaveInsertLink">
  </xsl:template>

  <xsl:template match="dvt_CancelEditLink">
  </xsl:template>

  <xsl:template match="dvt_CancelInsertLink">
  </xsl:template>

  <xsl:template match="dvt_EditLink">
  </xsl:template>

  <xsl:template match="dvt_DeleteLink">
  </xsl:template>

  <xsl:template match="dvt_SelectLink">
    <a href="#">
      <out:attribute name="onclick"><out:value-of select="ddwrt:GenFireServerEvent(concat('{$basename}_form_selectkey={{',$KeyValue,'}}'))"/>; return false;</out:attribute>
      <out:choose>
        <out:when>
          <xsl:attribute name="test">$<xsl:value-of select="$basename"/>_form_selectkey = @*[name()=$ColumnKey]</xsl:attribute>
          <img border="0" style="cursor: hand" src="/_layouts/images/rbsel.gif">
            <out:attribute name="alt">
              <out:value-of select="$SelectionRadioButtonToolTip"/>
            </out:attribute>
          </img>
        </out:when>
        <out:otherwise>
          <img border="0" style="cursor: hand" src="/_layouts/images/rbunsel.gif">
            <out:attribute name="alt">
              <out:value-of select="$SelectionRadioButtonToolTip"/>
            </out:attribute>
          </img>
        </out:otherwise>
      </out:choose>
    </a>
  </xsl:template>

  <xsl:template match="dvt_IfAutoMode">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="dvt_TDFieldView">
    <xsl:param name="ThisField"/>

    <td class="ms-vb">
      <out:attribute name="style">
        <out:choose>
          <out:when><xsl:attribute name="test">$<xsl:value-of select="$basename"/>_form_selectkey = @*[name()=$ColumnKey]</xsl:attribute>color:blue</out:when>
          <out:otherwise></out:otherwise>
        </out:choose>
      </out:attribute>

      <xsl:call-template name="gen-field-view">
        <xsl:with-param name="ThisField" select="$ThisField"/>
      </xsl:call-template>
    </td>
  </xsl:template>

  <xsl:template name="GenerateLFtoBR">
    <!-- trim leading and trailing line feeds from the input -->
    <out:template name="_trimLF">
      <out:param name="input"/>
      <out:choose>
        <out:when test="starts-with($input, '&#xA;')">
          <out:call-template name="_trimLF">
            <out:with-param name="input" select="substring($input, 2)"/>
          </out:call-template>
        </out:when>
        <out:when test="substring($input, string-length($input), 1) = '&#xA;'">
          <out:call-template name="_trimLF">
            <out:with-param name="input" select="substring($input, 1, string-length($input)-1)"/>
          </out:call-template>
        </out:when>
        <out:otherwise>
          <out:value-of select="$input"/>
        </out:otherwise>
      </out:choose>
    </out:template>

    <!-- replace line feeds with <br/> nodes -->
    <out:template name="_LFtoBRloop">
      <out:param name="input"/>
      <out:variable name="beforeText" select="substring-before($input, '&#xA;')"/>
      <out:choose>
        <out:when test="string-length($beforeText) = 0 and substring($input, 1, 1) != '&#xA;'">
          <out:value-of select="$input"/>
        </out:when>
        <out:otherwise>
          <out:value-of select="$beforeText"/><br/><out:call-template name="_LFtoBRloop">
            <out:with-param name="input" select="substring($input, string-length($beforeText)+2)"/>
          </out:call-template>
        </out:otherwise>
      </out:choose>
    </out:template>

    <!-- replace line feeds (except leading/trailing line feeds) with <br/> nodes. it works by:
      1. Eliminating carriage returns
      2. Trimming leading/trailing line feeds
      3. Splitting the input at line feed characters and replacing them with <br/> nodes
    -->
    <out:template name="LFtoBR">
      <out:param name="input"/>
      <out:choose>
        <out:when test="substring-before($input, '&#xA;') = ''"><!-- easy out if there are no line feeds -->
          <out:value-of select="$input"/>
        </out:when>
        <out:otherwise>
          <out:call-template name="_LFtoBRloop">
            <out:with-param name="input">
              <out:call-template name="_trimLF">
                <out:with-param name="input" select="translate($input, '&#xD;', '')"/>
              </out:call-template>
            </out:with-param>
          </out:call-template>
        </out:otherwise>
      </out:choose>
    </out:template>
  </xsl:template>

  <xsl:template name="GenerateFormatString">
    <out:template name="formatString">
      <out:param name="stringvalue"/>
      <out:param name="separator"/>
      <out:variable name="curStr" select="substring-after($stringvalue, $separator)"/>
      <out:choose>
        <out:when test="contains($curStr, $separator)">
          <out:value-of select="substring-before($stringvalue, $separator)"/>
          <out:value-of select="ddwrt:UrlEncode(@*[name()=substring-before($curStr, $separator)])"/>
          <out:call-template name="formatString">
            <out:with-param name="stringvalue" select="substring-after($curStr, $separator)"/>
            <out:with-param name="separator" select="$separator"/>
          </out:call-template>
        </out:when>
        <out:otherwise>
          <out:value-of select="$stringvalue"/>
        </out:otherwise>
      </out:choose>
    </out:template>
  </xsl:template>
  <xsl:template name="GenerateOpenActionsMenuScriptCall">
    <out:template name="OpenActionsMenu">
      <out:param name="method"/>
      <out:param name="id"/>
      <out:param name="menuText"/>

      <out:value-of select="$method"/>
      <out:text>('</out:text>
      <out:value-of select="$jsMenuLoadingMessage"/>
      <out:text>','</out:text>
      <out:value-of select="ddwrt:EcmaScriptEncode($menuText)"/>
      <out:text>',false,'</out:text>
      <out:value-of select="$jsMenuApplication"/>
      <out:text>','</out:text>
      <out:value-of select="$jsMenuEntityNamespace"/>
      <out:text>','</out:text>
      <out:value-of select="$jsMenuEntityName"/>
      <out:text>','</out:text>
      <out:value-of select="ddwrt:EcmaScriptEncode($id)"/>
      <out:text>', event);</out:text>
    </out:template>
  </xsl:template>
</xsl:stylesheet>

