
<xsl:stylesheet version="1.0" exclude-result-prefixes="RSdoc rd rdl " xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"
                xmlns:rdl="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" 
                xmlns:RSdoc="http://spacefold.com/RSdoc">

   <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

   <xsl:param name="forceFirstRowOn" select="true()"/>
   <xsl:param name="RSDocCustomPropertyNamePrefix" select="'RSdoc.'"/>
   <xsl:param name="verboseDelimiter" select="'|'"/>
   <xsl:param name="defaultRDLDocCustomCategoryName" select="'RSDocCustom'"/>
   <xsl:param name="defaultStandardItemCategoryName" select="'base'"/>
   <xsl:param name="designerItemDescriptionCategoryName" select="'itemDescription'"/>
   <xsl:param name="designerCustomItemCategoryName" select="$defaultRDLDocCustomCategoryName"/>
   <xsl:param name="designerItemVerboseCategoryName" select="concat($defaultRDLDocCustomCategoryName,' verbose')"/>

   <xsl:param name="rdlDocumenterType" select="'RDLDocumenter'"/>

  <!-- 
   Done:
     Custom props revamp for 2008/2010 ReportDesigner capabilities 
     Proper Tablix support
  
  TBD:
  Chart revamp
  Add R2-specific features (or is this a separate schema/XSLT?) such as shared datasets, report parts
  Add other features that are new in the schema,
  including Placeholders aka TextRun
  Add other features not included yet that seem interesting,
  such as NoRowsMessage (already done), whether new or not.
  -->

   <xsl:template match="/">
      <xmlRSDocsDataSet>
         <xsl:comment>xmlRSDocs-generated: Lisa Slater Nicholls, Spacefold, 2012</xsl:comment>

         <!-- handle global Report description and non-visual nodes such as Code under Report -->
         <xsl:apply-templates select="/rdl:Report" mode="globals"/>

        <!-- handle global (Report-level) custom properties of all types -->
        <xsl:call-template name="globalCustomProperties"/>

         <!-- handle main page regions with standard output, and also 
               all contained layout items that have been marked
               with Xmldocs-style documentation in our namespace if such has been added 
               (can't be done if standard ReportDesigner is in use, since they
               get blown away)  -->
         <xsl:apply-templates select="/rdl:Report/rdl:PageHeader" mode="layout"/>
         <xsl:apply-templates select="/rdl:Report/rdl:Body" mode="layout"/>
         <xsl:apply-templates select="/rdl:Report/rdl:PageFooter" mode="layout"/>


        <!-- handle drilldown custom properties of all types -->
        <xsl:call-template name="itemCustomProperties"/>

        <!-- handle some specialized documentation markup we support that is applied across elements -->
         <xsl:apply-templates select="/rdl:Report/*/*/descendant::*[name()='RSdoc:Sibling']/parent::*" mode="meta-sibling"/>
         <xsl:apply-templates select="/rdl:Report/*/*/descendant::*[name()='RSdoc:Children']/parent::*" mode="meta-children"/>

         <!-- reference any Subreports -->
         <xsl:apply-templates select="/rdl:Report/*/*/descendant::rdl:Subreport"/>
 
      </xmlRSDocsDataSet>
   </xsl:template>

   <xsl:template match="*" mode="globals">
      <xsl:apply-templates select="./rdl:Description">
         <!-- first item needs all columns for use in XML Data Source automatic schema discovery
          if you're using that-->
         <xsl:with-param name="forceOn" select="$forceFirstRowOn"/>
      </xsl:apply-templates>
      <xsl:apply-templates select="./rdl:Author"/>
      <xsl:apply-templates select="./rdl:Language[text()]"/>
      <xsl:apply-templates select="./rdl:DataTransform[text()]"/>
      <xsl:apply-templates select="./rdl:DataSchema[text()]"/>
      <xsl:apply-templates select="./rdl:DataElementName[text()]"/>
      <xsl:apply-templates select="./rdl:DataElementStyle[text()]"/>
      <xsl:apply-templates select="./rdl:Height[text()]"/>
      <xsl:apply-templates select="./rdl:Width[text()]"/>
      <xsl:apply-templates select="./rdl:PageHeight[text()]"/>
      <xsl:apply-templates select="./rdl:PageWidth[text()]"/>
      <xsl:apply-templates select="./rdl:InteractiveHeight[text()]"/>
      <xsl:apply-templates select="./rdl:InteractiveWidth[text()]"/>
      <xsl:apply-templates select="./rdl:LeftMargin[text()]"/>
      <xsl:apply-templates select="./rdl:RightMargin[text()]"/>
      <xsl:apply-templates select="./rdl:TopMargin[text()]"/>
      <xsl:apply-templates select="./rdl:BottomMargin[text()]"/>
      <xsl:apply-templates select="./rdl:DataSources/*"/>
      <xsl:apply-templates select="./rdl:DataSets/*"/>
      <xsl:apply-templates select="./rdl:ReportParameters/*"/>
      <xsl:apply-templates select="./rdl:Code"/>
      <xsl:apply-templates select="./rdl:CodeModules/*"/>
      <xsl:apply-templates select="./rdl:Classes/*"/>
   </xsl:template>

  <xsl:template name="globalCustomProperties">

    <!-- handle Report custom properties that do not belong to us -->


    <xsl:apply-templates select="/rdl:Report/rdl:CustomProperties/rdl:CustomProperty[not(starts-with(rdl:Name,
                              $RSDocCustomPropertyNamePrefix))]"/>


    <!-- handle Report custom properties, some of which may actually belong to descendants,
           created with name.syntax by our Designer facility or manually -->

    <xsl:apply-templates select="/rdl:Report/rdl:CustomProperties/rdl:CustomProperty[starts-with(rdl:Name,
                              $RSDocCustomPropertyNamePrefix)]" mode="rsDocProperties"/>


  </xsl:template>

  <xsl:template name="itemCustomProperties">

    <!-- handle custom properties stored against an RDLDocumenter node
            that actually belong to other nodes, 
            which may also be created with name.syntax by our Designer facility 
            Note that this isn't likely to happen in 2008 RDL, since we don't need an RDLDocumenter
            Custom Report Item anymore, but is left here JIC I create one.-->
    <xsl:apply-templates select="/rdl:Report/*/*/descendant::rdl:CustomReportItem
                             [./rdl:Type/text()= $rdlDocumenterType]/descendant::rdl:CustomProperty[starts-with(rdl:Name,$RSDocCustomPropertyNamePrefix)]"
                         mode="rsDocProperties"/>

    <!-- handle any CustomProperties elements owned by us, and not in the Report node, 
                that have been created against individual elements in CustomProperty nodes
                (the syntax is different, doesn't need the item name assignment since we're explicitly on the item in these cases) -->
    <xsl:apply-templates select="/rdl:Report/*/*/descendant::rdl:CustomProperty
                              [not(local-name(ancestor::*[2])='CustomReportItem' and ancestor::*[2]/rdl:Type/text()=$rdlDocumenterType) 
                              and starts-with(./*,$RSDocCustomPropertyNamePrefix)]" mode="rsDocProperties"/>
    
    <!-- handle any CustomProperties on an item level that don't belong to us -->

    <xsl:apply-templates select="/rdl:Report/*//rdl:CustomProperties/rdl:CustomProperty[not(starts-with(rdl:Name,
                              $RSDocCustomPropertyNamePrefix))]"/>


  </xsl:template>

   <xsl:template match="rdl:DataSource">
      <xsl:variable name="thisValue">
         <xsl:choose>
            <xsl:when test="string-length(concat(rdl:DataSourceReference,rdl:ConnectionProperties/rdl:ConnectString)) &gt; 0">
               <xsl:value-of select="normalize-space(concat(rdl:DataSourceReference,' ',rdl:ConnectionProperties/rdl:ConnectString))"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="@Name"/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>

      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="$thisValue"/>
         <xsl:with-param name="thisRDLLayoutType" select="'DataSource'"/>
         <xsl:with-param name="thisRDLLayoutName" select="@Name"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="'DataSources'"/>
         <xsl:with-param name="thisCategory"/>
      </xsl:call-template>
      <!-- tbd: add record for connection source, transaction ? -->
   </xsl:template>
   <xsl:template match="rdl:DataSet">
      <xsl:variable name="thisName" select="./@Name"/>

      <!-- tbd: add records for other query aspects, such as query parameters? -->
      <xsl:if test="string-length(normalize-space(./*/rdl:CommandText)) &gt; 0 ">
         <xsl:call-template name="DocRow">
            <xsl:with-param name="thisValue" select="./*/rdl:CommandText"/>
            <xsl:with-param name="thisRDLLayoutType" select="'CommandText'"/>
            <xsl:with-param name="thisRDLLayoutName" select="concat($thisName,'-CommandText')"/>
            <xsl:with-param name="thisRDLLayoutParentTag" select="'DataSet'"/>
            <xsl:with-param name="thisRDLLayoutParentName" select="$thisName"/>
         </xsl:call-template>
      </xsl:if>

      <xsl:for-each select="./*/rdl:Field">

         <xsl:call-template name="DocRow">
            <xsl:with-param name="thisValue" select="concat(./rdl:DataField,./rdl:Value)"/>
            <!-- this is a choice element -->
            <xsl:with-param name="thisRDLLayoutType" select="'Field'"/>
            <xsl:with-param name="thisRDLLayoutName" select="@Name"/>
            <xsl:with-param name="thisRDLLayoutParentTag" select="'DataSet'"/>
            <xsl:with-param name="thisRDLLayoutParentName" select="concat($thisName,'-Fields')"/>
         </xsl:call-template>
      </xsl:for-each>
   </xsl:template>

   <xsl:template match="rdl:CodeModule">
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="."/>
         <xsl:with-param name="thisRDLLayoutType" select="'CodeModule'"/>
         <xsl:with-param name="thisRDLLayoutName" select="'CodeModule'"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="'Report'"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="'Report'"/>
      </xsl:call-template>
   </xsl:template>

   <xsl:template match="rdl:Class">
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="./rdl:InstanceName"/>
         <xsl:with-param name="thisRDLLayoutType" select="'Class'"/>
         <xsl:with-param name="thisRDLLayoutName" select="./rdl:ClassName"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="'Classes'"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="'Classes'"/>
      </xsl:call-template>
   </xsl:template>

   <xsl:template match="rdl:Filter">
      <xsl:param name="parent"/>
      <xsl:param name="parenttype"/>
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="concat(translate(./rdl:FilterExpression,'=',''),' ',./rdl:Operator,' ', ./rdl:FilterValues/*)"/>
         <xsl:with-param name="thisRDLLayoutType" select="'Filter'"/>
         <xsl:with-param name="thisRDLLayoutName" select="concat($parent,'-Filter-',string(count(preceding-sibling::rdl:Filter) +1))"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="$parenttype"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="$parent"/>
      </xsl:call-template>
   </xsl:template>

  <xsl:template match="rdl:SortExpressions">
    <xsl:param name="parent" select="ancestor::*[4]/@Name"/>
    <xsl:param name="parenttype" select="concat(local-name(ancestor::*[4]),'-',local-name(ancestor::*[3]))"/>
    <xsl:for-each select="rdl:SortExpression">
      <xsl:call-template name="DocRow">
        <xsl:with-param name="thisValue" select="concat(./rdl:Value, ' ',rdl:Direction)"/>
        <xsl:with-param name="thisRDLLayoutType" select="'Sort'"/>
        <xsl:with-param name="thisRDLLayoutName" select="concat($parent,'-Sort-',string(position()))"/>
        <xsl:with-param name="thisRDLLayoutParentTag" select="$parenttype"/>
        <xsl:with-param name="thisRDLLayoutParentName" select="concat($parent,'-SortExpression')"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>

   <xsl:template match="rdl:Sorting">
      <xsl:param name="parent"/>
      <xsl:param name="parenttype"/>
      <xsl:for-each select="rdl:SortBy">
         <xsl:call-template name="DocRow">
            <xsl:with-param name="thisValue" select="concat(./rdl:SortExpression, ' ',rdl:Direction)"/>
            <xsl:with-param name="thisRDLLayoutType" select="'Sort'"/>
            <xsl:with-param name="thisRDLLayoutName" select="concat($parent,'-Sort-',string(position()))"/>
            <xsl:with-param name="thisRDLLayoutParentTag" select="$parenttype"/>
            <xsl:with-param name="thisRDLLayoutParentName" select="concat($parent,'-Sorting')"/>
         </xsl:call-template>
      </xsl:for-each>
   </xsl:template>

   <xsl:template match="rdl:GroupExpressions">
      <xsl:param name="parent"/>
      <xsl:param name="parenttype"/>
      <xsl:param name="grouptype"/>
      <xsl:variable name="groupname" select="../@Name"/>
      <xsl:for-each select="rdl:GroupExpression">
         <xsl:call-template name="DocRow">
            <xsl:with-param name="thisValue" select="text()"/>
            <xsl:with-param name="thisRDLLayoutType" select="'GroupExpression'"/>
            <xsl:with-param name="thisRDLLayoutName" select="concat($groupname,'-GroupExpression-',string(position()))"/>
            <xsl:with-param name="thisRDLLayoutParentTag" select="$grouptype"/>
            <xsl:with-param name="thisRDLLayoutParentName" select="concat($parent,'-',$grouptype)"/>
         </xsl:call-template>
      </xsl:for-each>
   </xsl:template>


   <xsl:template match="rdl:ReportParameter | rdl:Parameter">
      <xsl:param name="parent" select="'Report'"/>
      <xsl:variable name="thisName" select="concat('@',./@Name)"/>
       <xsl:variable name="thisParent" select="concat($parent,'-',$thisName)"/>

      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="./rdl:DataType"/>
         <xsl:with-param name="thisRDLLayoutType" select="'Parameter'"/>
         <xsl:with-param name="thisRDLLayoutName" select="$thisName"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="'Parameters'"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="$parent"/>
      </xsl:call-template>

      <!--  add records for still more parameter details ? -->
      <xsl:if test="./rdl:Hidden != 'true'">
         <xsl:call-template name="DocRow">
            <xsl:with-param name="thisValue" select="./rdl:Prompt"/>
            <xsl:with-param name="thisRDLLayoutType" select="'Prompt'"/>
            <xsl:with-param name="thisRDLLayoutName" select="concat($thisName,'-Prompt')"/>
            <xsl:with-param name="thisRDLLayoutParentTag" select="'Parameter'"/>
            <xsl:with-param name="thisRDLLayoutParentName" select="$thisParent"/>
         </xsl:call-template>
      </xsl:if>
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="./rdl:Nullable = true()"/>
         <xsl:with-param name="thisRDLLayoutType" select="'Nullable'"/>
         <xsl:with-param name="thisRDLLayoutName" select="concat($thisName,'-Nullable')"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="'Parameter'"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="$thisParent"/>
      </xsl:call-template>
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="./rdl:MultiValue  = true()"/>
         <xsl:with-param name="thisRDLLayoutType" select="'MultiValue'"/>
         <xsl:with-param name="thisRDLLayoutName" select="concat($thisName,'-MultiValue')"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="'Parameter'"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="$thisParent"/>
      </xsl:call-template>
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="./rdl:Hidden  = true()"/>
         <xsl:with-param name="thisRDLLayoutType" select="'Hidden'"/>
         <xsl:with-param name="thisRDLLayoutName" select="concat($thisName,'-Hidden')"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="'Parameter'"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="$thisParent"/>
      </xsl:call-template>
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="./rdl:UsedInQuery  = true()"/>
         <xsl:with-param name="thisRDLLayoutType" select="'UsedInQuery'"/>
         <xsl:with-param name="thisRDLLayoutName" select="concat($thisName,'-UsedInQuery')"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="'Parameter'"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="$thisParent"/>
      </xsl:call-template>
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="./rdl:AllowBlank  = true()"/>
         <xsl:with-param name="thisRDLLayoutType" select="'AllowBlank'"/>
         <xsl:with-param name="thisRDLLayoutName" select="concat($thisName,'-AllowBlank')"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="'Parameter'"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="$thisParent"/>
      </xsl:call-template>

      <xsl:if test="string-length(./rdl:DefaultValue) &gt; 0">
         <xsl:call-template name="DocRow">
            <xsl:with-param name="thisValue" select="./rdl:DefaultValue"/>
            <xsl:with-param name="thisRDLLayoutType" select="'DefaultValue'"/>
            <xsl:with-param name="thisRDLLayoutName" select="concat($thisName,'-DefaultValue')"/>
            <xsl:with-param name="thisRDLLayoutParentTag" select="'Parameter'"/>
            <xsl:with-param name="thisRDLLayoutParentName" select="$thisParent"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>

   <xsl:template match="rdl:Code">
      <xsl:if test="string-length(normalize-space(./text())) &gt; 0">
         <xsl:call-template name="DocRow">
            <xsl:with-param name="thisValue" select="./text()"/>
            <xsl:with-param name="thisRDLLayoutType" select="'Code'"/>
            <xsl:with-param name="thisRDLLayoutName" select="'Code'"/>
            <xsl:with-param name="thisRDLLayoutParentTag" select="'Report'"/>
            <xsl:with-param name="thisRDLLayoutParentName" select="'Report'"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>

   <xsl:template match="rdl:Line | rdl:Rectangle | rdl:Image | rdl:Textbox ">
   <!-- there isn't much done for these items by default for now, you have to mark them as verbose normally-->
      <xsl:if test=".//rdl:Action">
         <xsl:variable name="thisActionType" select="local-name(.//rdl:Action/*[contains('HyperlinkBookmarkLinkDrillthrough',local-name())][1])"/>
         <xsl:call-template name="DocRow">
            <xsl:with-param name="thisTag" select="'clickableAction'"/>
            <xsl:with-param name="thisParentTag" select="'designerDetails'"/>
            <xsl:with-param name="thisValue" select=".//*[local-name(.) = $thisActionType]/descendant-or-self::*[string-length(normalize-space(text())) &gt; 0][1]/text()"/>
            <xsl:with-param name="thisRDLLayoutType" select="'Action'"/>
            <xsl:with-param name="thisRDLLayoutName" select="concat('Action-',$thisActionType)"/>
            <xsl:with-param name="thisRDLLayoutParentTag" select="local-name(.)"/>
            <xsl:with-param name="thisRDLLayoutParentName" select="@Name"/>
            <xsl:with-param name="thisCategory" select="$designerItemVerboseCategoryName"/>
            <xsl:with-param name="thisItem" select="."/>
         </xsl:call-template>
      </xsl:if>


   </xsl:template>

   <xsl:template match="rdl:CustomReportItem">
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="./rdl:Type"/>
         <xsl:with-param name="thisRDLLayoutType" select="'CustomReportItem'"/>
         <xsl:with-param name="thisRDLLayoutName" select="@Name"/>
          <xsl:with-param name="thisRDLLayoutParentTag" select="local-name(..)"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="../@Name|rdl:Name"/>
      </xsl:call-template>
   </xsl:template>

   <xsl:template match="rdl:Subreport">

      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="./rdl:ReportName"/>
         <xsl:with-param name="thisRDLLayoutType" select="'Subreport'"/>
         <xsl:with-param name="thisRDLLayoutName" select="@Name"/>
          <xsl:with-param name="thisRDLLayoutParentTag" select="local-name(..)"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="../@Name"/>
      
      </xsl:call-template>

      <xsl:call-template name="Dimensions"/>

      <xsl:apply-templates select="./rdl:Parameters/*">
         <xsl:with-param name="parent" select="@Name"/>
      </xsl:apply-templates>
   </xsl:template>

   <xsl:template match="rdl:Table | rdl:Matrix | rdl:List | rdl:Chart | rdl:Tablix ">

     <xsl:call-template name="Dimensions"/>
     
     <xsl:call-template name="DataDef">
         <xsl:with-param name="parent" select="@Name"/>
         <xsl:with-param name="parenttype" select="local-name()"/>
      </xsl:call-template>

     <xsl:call-template name="NoDataRowsMessage">
       <xsl:with-param name="parent" select="@Name"/>
       <xsl:with-param name="parenttype" select="local-name()"/>
     </xsl:call-template>

     <xsl:call-template name="Sorts">
         <xsl:with-param name="parent" select="@Name"/>
         <xsl:with-param name="parenttype" select="local-name()"/>
      </xsl:call-template>

      <xsl:call-template name="Groups">
         <xsl:with-param name="parent" select="@Name"/>
         <xsl:with-param name="parenttype" select="local-name()"/>
      </xsl:call-template>

      <xsl:apply-templates select="rdl:Filters/*">
         <xsl:with-param name="parent" select="@Name"/>
         <xsl:with-param name="parenttype" select="local-name()"/>
      </xsl:apply-templates>

  


     <!-- tbd: detail group for tables and lists , does this actually do anything useful??
       also filters on groups are not included in the docs so far.-->
   </xsl:template>

   <xsl:template name="Groups">
      <xsl:param name="parent"/>
      <xsl:param name="parenttype"/>
      <xsl:choose>
         <xsl:when test="$parenttype = 'List'">
            <xsl:apply-templates select="rdl:Grouping/rdl:GroupExpressions">
               <xsl:with-param name="parent" select="$parent"/>
               <xsl:with-param name="parenttype" select="$parenttype"/>
               <xsl:with-param name="grouptype" select="'Grouping'"/>
            </xsl:apply-templates>
         </xsl:when>
         <xsl:when test="$parenttype='Table'">
            <xsl:apply-templates select="rdl:TableGroups/*/*/rdl:GroupExpressions">
               <xsl:with-param name="parent" select="$parent"/>
               <xsl:with-param name="parenttype" select="$parenttype"/>
               <xsl:with-param name="grouptype" select="'TableGroup'"/>
            </xsl:apply-templates>
         </xsl:when>
         <xsl:when test="$parenttype='Chart'">
            <xsl:apply-templates select="rdl:SeriesGroupings/*/*/*/rdl:GroupExpressions">
               <xsl:with-param name="parent" select="$parent"/>
               <xsl:with-param name="parenttype" select="$parenttype"/>
               <xsl:with-param name="grouptype" select="'SeriesGrouping'"/>
            </xsl:apply-templates>
            <xsl:apply-templates select="rdl:CategoryGroupings/*/*/*/rdl:GroupExpressions">
               <xsl:with-param name="parent" select="$parent"/>
               <xsl:with-param name="parenttype" select="$parenttype"/>
               <xsl:with-param name="grouptype" select="'CategoryGrouping'"/>
            </xsl:apply-templates>
         </xsl:when>
        <xsl:when test="$parenttype='Tablix'">
          <xsl:apply-templates select="rdl:TablixRowHierarchy/*/*/*/rdl:GroupExpressions">
            <xsl:with-param name="parent" select="$parent"/>
            <xsl:with-param name="parenttype" select="$parenttype"/>
            <xsl:with-param name="grouptype" select="'RowGrouping'"/>
          </xsl:apply-templates>
          <xsl:apply-templates select="rdl:TablixRowHierarchy/*/*/*/rdl:Filters/*">
            <xsl:with-param name="parent" select="$parent"/>
            <xsl:with-param name="parenttype" select="concat($parenttype,'-RowGroup')"/>
          </xsl:apply-templates>
          <xsl:apply-templates select="rdl:TablixColumnHierarchy/*/*/*/rdl:GroupExpressions">
            <xsl:with-param name="parent" select="$parent"/>
            <xsl:with-param name="parenttype" select="$parenttype"/>
            <xsl:with-param name="grouptype" select="'ColumnGrouping'"/>
          </xsl:apply-templates>
          <xsl:apply-templates select="rdl:TablixColumnHierarchy/*/*/*/rdl:Filters/*">
            <xsl:with-param name="parent" select="$parent"/>
            <xsl:with-param name="parenttype" select="concat($parenttype,'-ColumnGroup')"/>
          </xsl:apply-templates>
        </xsl:when>
          <xsl:when test="$parenttype='Matrix'">
            <xsl:apply-templates select="rdl:RowGroupings/*/*/*/rdl:GroupExpressions">
               <xsl:with-param name="parent" select="$parent"/>
               <xsl:with-param name="parenttype" select="$parenttype"/>
               <xsl:with-param name="grouptype" select="'RowGrouping'"/>
            </xsl:apply-templates>
            <xsl:apply-templates select="rdl:ColumnGroupings/*/*/*/rdl:GroupExpressions">
               <xsl:with-param name="parent" select="$parent"/>
               <xsl:with-param name="parenttype" select="$parenttype"/>
               <xsl:with-param name="grouptype" select="'ColumnGrouping'"/>
            </xsl:apply-templates>
         </xsl:when>
      </xsl:choose>

     
   </xsl:template>

   <xsl:template name="Dimensions">

      <xsl:apply-templates select="rdl:Top[text()]"/>
      <xsl:apply-templates select="rdl:Left[text()]"/>
      <xsl:apply-templates select="rdl:Height[text()]"/>
      <xsl:apply-templates select="rdl:Width[text()]"/>
   
   </xsl:template>

   <xsl:template name="DataDef">
      <xsl:param name="parent"/>
      <xsl:param name="parenttype"/>

      <!-- TBD: could do more here with Data Output tab, need to pay attention by parent type if we do -->
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="rdl:DataSetName"/>
         <xsl:with-param name="thisRDLLayoutType" select="'DataSetName'"/>
         <xsl:with-param name="thisRDLLayoutName" select="concat($parent,'-DataSetName')"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="$parenttype"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="$parent"/>
      </xsl:call-template>
   </xsl:template>


  <xsl:template name="NoDataRowsMessage">
    <xsl:param name="parent"/>
    <xsl:param name="parenttype"/>
    <xsl:if test="string-length(normalize-space(rdl:NoRowsMessage)) &gt; 0">
    <xsl:call-template name="DocRow">
      <xsl:with-param name="thisValue" select="rdl:NoRowsMessage"/>
      <xsl:with-param name="thisRDLLayoutType" select="'NoRowsMessage'"/>
      <xsl:with-param name="thisRDLLayoutName" select="concat($parent,'-NoRowsMessage')"/>
      <xsl:with-param name="thisRDLLayoutParentTag" select="$parenttype"/>
      <xsl:with-param name="thisRDLLayoutParentName" select="$parent"/>
    </xsl:call-template>
    </xsl:if>
  </xsl:template>


    <xsl:template name="Sorts">
      <xsl:param name="parent"/>
      <xsl:param name="parenttype"/>
      <xsl:choose>
         <xsl:when test="$parenttype = 'List'">
            <xsl:apply-templates select="rdl:Sorting">
               <xsl:with-param name="parent" select="$parent"/>
               <xsl:with-param name="parenttype" select="$parenttype"/>
            </xsl:apply-templates>
         </xsl:when>
         <xsl:when test="$parenttype='Table'">
            <xsl:apply-templates select="rdl:Details/rdl:Sorting">
               <xsl:with-param name="parent" select="$parent"/>
               <xsl:with-param name="parenttype" select="$parenttype"/>
            </xsl:apply-templates>
         </xsl:when>
         <xsl:when test="$parenttype='Chart'">
            <!-- ?? -->
         </xsl:when>
        <xsl:when test="$parenttype='Tablix'">
          <xsl:apply-templates select="rdl:SortExpressions">
            <xsl:with-param name="parent" select="$parent"/>
            <xsl:with-param name="parenttype" select="$parenttype"/>
          </xsl:apply-templates>
          <xsl:apply-templates select="./*/rdl:TablixMembers/rdl:TablixMember/rdl:SortExpressions"/>
        </xsl:when>
         <xsl:when test="$parenttype='Matrix'">
            <xsl:apply-templates select="rdl:RowGroupings/*/*/rdl:Sorting">
               <xsl:with-param name="parent" select="$parent"/>
               <xsl:with-param name="parenttype" select="$parenttype"/>
            </xsl:apply-templates>
            <xsl:apply-templates select="rdl:ColumnGroupings/*/*/rdl:Sorting">
               <xsl:with-param name="parent" select="$parent"/>
               <xsl:with-param name="parenttype" select="$parenttype"/>
            </xsl:apply-templates>
         </xsl:when>
      </xsl:choose>
   </xsl:template>


   <xsl:template match="*" mode="rsDocProperties">
      <!-- handle verbose property separately from all others -->
      <xsl:choose>
         <xsl:when test="rdl:Name = concat($RSDocCustomPropertyNamePrefix,'verbose') and local-name(../..) = 'Report'">
            <xsl:call-template name="verboseItems"/>
         </xsl:when>
        <xsl:when test="rdl:Name = concat($RSDocCustomPropertyNamePrefix,'verbose')">
          <xsl:call-template name="singleVerboseItem">
            <xsl:with-param name="thisItem" select="../.."/>
            <xsl:with-param name="thisName" select="../../@Name"/>
          </xsl:call-template>
        </xsl:when>
         <xsl:otherwise>
            <xsl:variable name="thisName" select="translate(substring-after(rdl:Name,$RSDocCustomPropertyNamePrefix),'*','')"/>
            <xsl:variable name="thisItem" select="//*[./@Name=$thisName][1]"/>
            <xsl:choose>
               <xsl:when test="$thisItem">
                  <xsl:variable name="thisParent" select="$thisItem/ancestor::*[contains('rdl:Table | rdl:Matrix | rdl:List | rdl:Chart | rdl:Tablix',local-name(.))][1]"/>
                  <xsl:call-template name="DocRow">
                     <xsl:with-param name="thisTag" select="'designerDescription'"/>
                     <xsl:with-param name="thisParentTag" select="''"/>
                     <xsl:with-param name="thisValue" select="rdl:Value"/>
                     <xsl:with-param name="thisRDLLayoutType" select="local-name($thisItem)"/>
                     <xsl:with-param name="thisRDLLayoutName" select="$thisName"/>
                     <xsl:with-param name="thisRDLLayoutParentTag" select="local-name($thisParent)"/>
                      <xsl:with-param name="thisRDLLayoutParentName" select="$thisParent/@Name|rdl:Name"/>
                     <xsl:with-param name="thisCategory" select="$designerItemDescriptionCategoryName"/>
                     <xsl:with-param name="thisItem" select="$thisItem"/>
                  </xsl:call-template>
               </xsl:when>
               <xsl:when test="false()">
                  <!-- we may have specific-to-item custom properties added through designer later -->
               </xsl:when>
               <xsl:otherwise>
                  <!-- global-custom property added through designer -->
                  <xsl:variable name="thisProperty">
                     <xsl:choose>
                        <xsl:when test="$thisName='Report'">
                           <xsl:value-of select="designerItemDescriptionCategoryName"/>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:value-of select="$thisName"/>
                        </xsl:otherwise>
                     </xsl:choose>
                  </xsl:variable>
                  <xsl:call-template name="DocRow">
                     <xsl:with-param name="thisTag" select="'designerCustom'"/>
                     <xsl:with-param name="thisParentTag" select="''"/>
                     <xsl:with-param name="thisValue" select="rdl:Value"/>
                     <xsl:with-param name="thisRDLLayoutType" select="'Report-Custom'"/>
                     <xsl:with-param name="thisRDLLayoutName" select="$thisName"/>
                     <xsl:with-param name="thisRDLLayoutParentTag" select="'Report'"/>
                     <xsl:with-param name="thisCategory" select="$defaultRDLDocCustomCategoryName"/>
                  </xsl:call-template>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="verboseItems">
      <xsl:param name="itemList" select="substring-after(translate(rdl:Value,' ',''),$verboseDelimiter)"/>
      <xsl:variable name="thisName" select="substring-before($itemList,$verboseDelimiter)"/>
      <xsl:variable name="thisItem" select="//*[@Name = $thisName][1]"/>
     <xsl:if test="$thisItem">
       <xsl:call-template name="singleVerboseItem">
         <xsl:with-param name="thisItem" select="$thisItem"/>
         <xsl:with-param name="thisName" select="$thisName"/>
       </xsl:call-template>
     </xsl:if>
   
      <xsl:if test="string-length(substring-after($itemList,$thisName)) &gt; 2">
         <xsl:call-template name="verboseItems">
            <xsl:with-param name="itemList" select="substring-after($itemList,concat($thisName,$verboseDelimiter,$verboseDelimiter))"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>

  <xsl:template name="singleVerboseItem">
    <xsl:param name ="thisItem"/>
     <xsl:param name ="thisName"/>
    
    <xsl:variable name="thisType" select="local-name($thisItem)"/>

    <xsl:variable name="thisParent" >
      <xsl:choose>
        <xsl:when test="($thisType='Textbox') and (string-length($thisItem/rdl:Value) = 0)">
          <xsl:value-of select="local-name($thisItem/ancestor::*[
                        contains('rdl:Body | rdl:PageFooter | rdl:PageHeader | rdl:Table | rdl:Matrix | rdl:List | rdl:Chart | rdl:Tablix',local-name(.))][1])"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="local-name($thisItem/ancestor::*[1])"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>


    <xsl:variable name="thisParentName" >
      <xsl:choose>
        <xsl:when test="($thisType='Textbox') and (string-length($thisItem/rdl:Value) = 0)">
          <xsl:value-of select="$thisItem/ancestor::*[
                        contains('rdl:Body | rdl:PageFooter | rdl:PageHeader | rdl:Table | rdl:Matrix | rdl:List | rdl:Chart | rdl:Tablix',local-name(.))][1]/@Name"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$thisItem/ancestor::*[1]/@Name|rdl:Name"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

      <!-- TBD: what special/distinct thing can verbose mean for various types of report items? here we just assume the same for all types-->
      <xsl:variable name="thisDetail">
        <xsl:choose>
          <xsl:when test="($thisType = 'Textbox') and (string-length(normalize-space($thisItem/rdl:Value)) &gt; 0)">
            <xsl:value-of select="$thisItem/rdl:Value"/>
          </xsl:when>
          <xsl:when test="$thisType = 'Textbox'">
            <!-- placeholders/textruns -->
            <xsl:for-each select="$thisItem/rdl:Paragraphs/*/rdl:TextRuns/*">
              <xsl:variable name="thisLabel">
                <xsl:if test="string-length(./rdl:Label) &gt; 0">
                  <xsl:value-of select="concat('[',./rdl:Label,'] ')"    />
                </xsl:if>
              </xsl:variable>
              <xsl:value-of select="concat($thisLabel,./rdl:Value)"/>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$thisType = 'Chart'">
            <xsl:value-of select="$thisItem/rdl:Type"/>
            <xsl:if test="string-length($thisItem/rdl:Subtype) &gt; 0">
              -<xsl:value-of select="$thisItem/rdl:Subtype"/>
            </xsl:if>
          </xsl:when>
          <xsl:when test="$thisType = 'CustomReportItem'">
          </xsl:when>
          <xsl:when test="contains('Line,Rectangle',$thisType)">
          </xsl:when>
          <xsl:when test="$thisType = 'Image'">
          </xsl:when>
          <xsl:when test="$thisType = 'Subreport'">
          </xsl:when>
          <xsl:when test="contains('Matrix,Table,List,Tablix',$thisType)">
          </xsl:when>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="thisDocTag">
        <xsl:choose>
          <xsl:when test="$thisType = 'Textbox' or string-length($thisItem/rdl:Value) &gt; 0">Expression</xsl:when>
          <xsl:when test="$thisType = 'Chart'">ChartType</xsl:when>
          <xsl:when test="$thisType = 'CustomReportItem'">
          </xsl:when>
          <xsl:when test="contains('Line,Rectangle',$thisType)">
          </xsl:when>
          <xsl:when test="$thisType = 'Image'">
          </xsl:when>
          <xsl:when test="$thisType = 'Subreport'">
          </xsl:when>
          <xsl:when test="contains('Matrix,Table,List,Tablix',$thisType)">
          </xsl:when>
        </xsl:choose>
      </xsl:variable>
      <xsl:if test="string-length(normalize-space($thisDetail)) &gt; 0">
        <xsl:call-template name="DocRow">
          <xsl:with-param name="thisTag" select="$thisDocTag"/>
          <xsl:with-param name="thisParentTag" select="'designerDetails'"/>
          <xsl:with-param name="thisValue" select="$thisDetail"/>
          <xsl:with-param name="thisRDLLayoutType" select="$thisType"/>
          <xsl:with-param name="thisRDLLayoutName" select="$thisName"/>
          <xsl:with-param name="thisRDLLayoutParentTag" select="$thisParent"/>
          <xsl:with-param name="thisRDLLayoutParentName" select="$thisParentName"/>          
          <xsl:with-param name="thisCategory" select="$designerItemVerboseCategoryName"/>
          <xsl:with-param name="thisItem" select="$thisItem"/>
        </xsl:call-template>
      </xsl:if>
      <xsl:if test="$thisItem/rdl:Visibility/rdl:Hidden">
        <xsl:call-template name="DocRow">
          <xsl:with-param name="thisTag" select="$thisDocTag"/>
          <xsl:with-param name="thisParentTag" select="'designerDetails'"/>
          <xsl:with-param name="thisValue" select="$thisItem/rdl:Visibility/rdl:Hidden"/>
          <xsl:with-param name="thisRDLLayoutType" select="'Visibility-Hidden'"/>
          <xsl:with-param name="thisRDLLayoutName" select="concat($thisItem/@Name,'-Visibility')"/>
          <xsl:with-param name="thisRDLLayoutParentTag" select="$thisParent"/>
          <xsl:with-param name="thisRDLLayoutParentName" select="$thisParentName"/>
          <xsl:with-param name="thisCategory" select="$designerItemVerboseCategoryName"/>
          <xsl:with-param name="thisItem" select="$thisItem"/>
        </xsl:call-template>
      </xsl:if>
      <xsl:if test="$thisItem/rdl:Visibility/rdl:ToggleItem">
        <xsl:call-template name="DocRow">
          <xsl:with-param name="thisTag" select="$thisDocTag"/>
          <xsl:with-param name="thisParentTag" select="'designerDetails'"/>
          <xsl:with-param name="thisValue" select="$thisItem/rdl:Visibility/rdl:ToggleItem"/>
          <xsl:with-param name="thisRDLLayoutType" select="'Visibility-ToggleItem'"/>
          <xsl:with-param name="thisRDLLayoutName" select="concat($thisItem/@Name,'-ToggleItem')"/>
          <xsl:with-param name="thisRDLLayoutParentTag" select="$thisParent"/>
          <xsl:with-param name="thisRDLLayoutParentName" select="$thisParentName"/>
          <xsl:with-param name="thisCategory" select="$designerItemVerboseCategoryName"/>
          <xsl:with-param name="thisItem" select="$thisItem"/>
        </xsl:call-template>
      </xsl:if>

      <xsl:if test="$thisItem/rdl:ToolTip">
        <xsl:call-template name="DocRow">
          <xsl:with-param name="thisTag" select="$thisDocTag"/>
          <xsl:with-param name="thisParentTag" select="'designerDetails'"/>
          <xsl:with-param name="thisValue" select="$thisItem/rdl:ToolTip"/>
          <xsl:with-param name="thisRDLLayoutType" select="'ToolTip'"/>
          <xsl:with-param name="thisRDLLayoutName" select="concat($thisItem/@Name,'-ToolTip')"/>
          <xsl:with-param name="thisRDLLayoutParentTag" select="$thisParent"/>
          <xsl:with-param name="thisRDLLayoutParentName" select="$thisParentName"/>
          <xsl:with-param name="thisCategory" select="$designerItemVerboseCategoryName"/>
          <xsl:with-param name="thisItem" select="$thisItem"/>
        </xsl:call-template>
      </xsl:if>

      <xsl:if test="$thisItem/rdl:Bookmark">
        <xsl:call-template name="DocRow">
          <xsl:with-param name="thisTag" select="$thisDocTag"/>
          <xsl:with-param name="thisParentTag" select="'designerDetails'"/>
          <xsl:with-param name="thisValue" select="$thisItem/rdl:Bookmark"/>
          <xsl:with-param name="thisRDLLayoutType" select="'Bookmark'"/>
          <xsl:with-param name="thisRDLLayoutName" select="concat($thisItem/@Name,'-Bookmark')"/>
          <xsl:with-param name="thisRDLLayoutParentTag" select="$thisParent"/>
          <xsl:with-param name="thisRDLLayoutParentName" select="$thisParentName"/>
          <xsl:with-param name="thisCategory" select="$designerItemVerboseCategoryName"/>
          <xsl:with-param name="thisItem" select="$thisItem"/>
        </xsl:call-template>
      </xsl:if>
     
    
  </xsl:template>

   <xsl:template match="*" mode="layout">
      <xsl:apply-templates select="rdl:Height[text()]">
         <xsl:with-param name="RDLLayoutName" select="concat(local-name(),'-Height')"/>
       </xsl:apply-templates>

      <xsl:apply-templates select="rdl:Width[text()]">
         <xsl:with-param name="RDLLayoutName" select="concat(local-name(),'-Width')"/>
      </xsl:apply-templates>

      <xsl:apply-templates select="rdl:Columns[text()]">
         <xsl:with-param name="RDLLayoutName" select="concat(local-name(),'-Columns')"/>
      </xsl:apply-templates>

      <xsl:apply-templates select="rdl:ColumnSpacing[text()]">
         <xsl:with-param name="RDLLayoutName" select="concat(local-name(),'-ColumnSpacing')"/>
      </xsl:apply-templates>


      <!-- now handle any namespaced doc elements for this node and its descendants that pertain to single elements -->
      <xsl:apply-templates select="descendant-or-self::*[contains(name(),'RSdoc:') and   not(contains('SiblingChildren',local-name(.)))]/ 
                           descendant-or-self::*[not(contains('SiblingChildren',local-name(.)))]"
                           mode="RSdoc"/>

      <!-- for data regions and anything we define standard-behavior all the way down the tree;
             must not include anything needing specialized treatment -->
      <xsl:call-template name="standard"/>

   </xsl:template>

   <xsl:template name="standard">
     <xsl:apply-templates select="descendant::rdl:Tablix"/>
     <xsl:apply-templates select="descendant::rdl:Table"/>
      <xsl:apply-templates select="descendant::rdl:Matrix"/>
      <xsl:apply-templates select="descendant::rdl:List"/>
      <xsl:apply-templates select="descendant::rdl:Chart"/>
      <xsl:apply-templates select="descendant::rdl:CustomReportItem"/>
      <xsl:apply-templates select="descendant::rdl:Textbox"/>
      <xsl:apply-templates select="descendant::rdl:Image"/>
     </xsl:template>

   <xsl:template name="base" match="*">
      <xsl:param name="Value" select="text()"/>
      <xsl:param name="RDLLayoutType" select="local-name(.)"/>
      <xsl:param name="RDLLayoutName" select="./@Name"/>
      <xsl:param name="RDLLayoutParentTag" select="local-name(parent::*)"/>
      <xsl:param name="RDLLayoutParentName" select="parent::*/@Name"/>
      <xsl:param name="forceOn"/>

      <xsl:variable name="thisValue">
         <xsl:choose>
            <!-- TBD: different values for other stuff like datasources ?-->
            <xsl:when test="local-name()='rdl:ReportParameter'">
               <xsl:value-of select="descendant-or-self::rdl:Value[1]/text()"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="$Value"/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>

      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisValue" select="$thisValue"/>
         <xsl:with-param name="thisRDLLayoutType" select="$RDLLayoutType"/>
         <xsl:with-param name="thisRDLLayoutName" select="$RDLLayoutName"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="$RDLLayoutParentTag"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="$RDLLayoutParentName"/>
         <xsl:with-param name="forceOn" select="$forceOn"/>
      </xsl:call-template>
   </xsl:template>

   <xsl:template match="*" mode="RSdoc">
      <xsl:param name="forceOn"/>
      <xsl:param name="thisDocTag" select="local-name(.)"/>
      <xsl:param name="thisValue" select="text()[1]"/>

      <xsl:choose>

         <xsl:when test="ancestor::*[contains(name(),'RSdoc:')]">
            <!-- this is a nested xmldoc tag -->
            <xsl:call-template name="DocRow">
               <xsl:with-param name="thisTag" select="$thisDocTag"/>
               <xsl:with-param name="thisParentTag" select="local-name(parent::*[1])"/>
               <xsl:with-param name="thisValue" select="$thisValue"/>
               <xsl:with-param name="thisRDLLayoutType" select="local-name(ancestor::*[2])"/>
               <xsl:with-param name="thisRDLLayoutName" select="ancestor::*[2]/@Name"/>
               <xsl:with-param name="thisRDLLayoutParentTag" select="local-name(ancestor::*[3])"/>
               <xsl:with-param name="thisRDLLayoutParentName" select="ancestor::*/@Name[3]"/>
               <xsl:with-param name="forceOn" select="$forceOn"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <!-- this is an xmldoc tag, but it might be a parent, so don't call if it has no content of its own -->
            <xsl:if test="string-length(normalize-space($thisValue)) &gt; 0">
               <xsl:call-template name="DocRow">
                  <xsl:with-param name="thisTag" select="$thisDocTag"/>
                  <xsl:with-param name="thisValue" select="$thisValue"/>
                  <xsl:with-param name="thisRDLLayoutType" select="local-name(ancestor::*[1])"/>
                  <xsl:with-param name="thisRDLLayoutName" select="ancestor::*[1]/@Name"/>
                  <xsl:with-param name="thisRDLLayoutParentTag" select="local-name(ancestor::*[2])"/>
                  <xsl:with-param name="thisRDLLayoutParentName" select="ancestor::*/@Name[2]"/>
                  <xsl:with-param name="forceOn" select="$forceOn"/>
               </xsl:call-template>
            </xsl:if>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template match="rdl:CustomProperty">
      <xsl:call-template name="DocRow">
         <xsl:with-param name="thisTag" select="substring-after(./rdl:Name,$RSDocCustomPropertyNamePrefix)"/>
         <xsl:with-param name="thisValue" select="./rdl:Value/text()"/>
         <xsl:with-param name="thisRDLLayoutType" select="local-name(.)"/>
         <xsl:with-param name="thisRDLLayoutName" select="./rdl:Name/text()"/>
         <xsl:with-param name="thisRDLLayoutParentTag" select="local-name(ancestor::*[2])"/>
         <xsl:with-param name="thisRDLLayoutParentName" select="ancestor::*[2]/@Name"/>
      </xsl:call-template>
   </xsl:template>

   <xsl:template name="DocRow">
      <xsl:param name="thisTag"/>
      <xsl:param name="thisParentTag"/>
      <xsl:param name="thisValue"/>
      <xsl:param name="thisRDLLayoutType"/>
      <xsl:param name="thisRDLLayoutName"/>
      <xsl:param name="thisRDLLayoutParentTag"/>
      <xsl:param name="thisRDLLayoutParentName"/>
      <xsl:param name="forceOn" select="false()"/>
      <xsl:param name="thisCategory"/>
      <xsl:param name="thisItem" select="."/>
      <xsl:param name="observeCRS" select="false()"/>

      <RDLDocPrimary>
         <DocTag>
            <xsl:value-of select="$thisTag"/>
            <xsl:if test="$forceOn and string-length($thisTag) = 0">
               <xsl:text disable-output-escaping="yes">&amp;#x00A0;</xsl:text>
            </xsl:if>
         </DocTag>
         <DocParentTag>
            <xsl:value-of select="$thisParentTag"/>
            <xsl:if test="$forceOn and string-length($thisParentTag) = 0">
               <xsl:text disable-output-escaping="yes">&amp;#x00A0;</xsl:text>
            </xsl:if>
         </DocParentTag>
         <Value>
            <xsl:value-of select="$thisValue"/>
            <xsl:if test="$forceOn and string-length($thisValue) = 0">
               <xsl:text disable-output-escaping="yes">&amp;#x00A0;</xsl:text>
            </xsl:if>
         </Value>
         <ParseableValue>
            <xsl:value-of select="normalize-space($thisValue)"/>
            <xsl:if test="$forceOn and string-length(normalize-space($thisValue)) = 0">
               <xsl:text disable-output-escaping="yes">&amp;#x00A0;</xsl:text>
            </xsl:if>
         </ParseableValue>
         <RDLLayoutType>
            <xsl:value-of select="$thisRDLLayoutType"/>
         </RDLLayoutType>
         <RDLLayoutName>
            <xsl:call-template name="layoutName">
               <xsl:with-param name="thisRDLLayoutName" select="$thisRDLLayoutName"/>
               <xsl:with-param name="thisRDLLayoutTag" select="$thisRDLLayoutType"/>
               <xsl:with-param name="thisItem" select="$thisItem"/>
            </xsl:call-template>
         </RDLLayoutName>
         <RDLLayoutParentTag>
            <xsl:value-of select="$thisRDLLayoutParentTag"/>
         </RDLLayoutParentTag>
         <RDLLayoutParentName>
            <xsl:call-template name="layoutName">
               <xsl:with-param name="thisRDLLayoutName" select="$thisRDLLayoutParentName"/>
               <xsl:with-param name="thisRDLLayoutTag" select="$thisRDLLayoutParentTag"/>
               <xsl:with-param name="thisItem" select="$thisItem"/>
            </xsl:call-template>
         </RDLLayoutParentName>
         <RDLCategory>
            <xsl:choose>
               <xsl:when test="$thisCategory and string-length(normalize-space($thisCategory)) &gt; 0">
                  <xsl:value-of select="$thisCategory"/>
               </xsl:when>
               <xsl:when test="$thisTag and string-length(normalize-space($thisTag)) &gt; 0">
                  <xsl:value-of select="$defaultRDLDocCustomCategoryName"/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:value-of select="$defaultStandardItemCategoryName"/>
               </xsl:otherwise>
            </xsl:choose>
         </RDLCategory>
      </RDLDocPrimary>
   </xsl:template>

   <xsl:template name="layoutName">
      <xsl:param name="thisRDLLayoutName"/>
      <xsl:param name="thisRDLLayoutTag"/>
      <xsl:param name="thisItem" select="."/>
      <xsl:choose>
         <xsl:when test="string-length($thisRDLLayoutName) &gt; 0">
            <xsl:value-of select="$thisRDLLayoutName"/>
         </xsl:when>
         <xsl:when test="$thisRDLLayoutTag='ReportItems'">
            <xsl:value-of select="concat(local-name($thisItem/ancestor::*[contains('|PageHeader|PageFooter|Body|',concat('|',local-name(),'|'))]),'-',$thisRDLLayoutTag)"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="$thisRDLLayoutTag"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>



   <xsl:template match="*" mode="meta-sibling">
      <xsl:variable name="thisNode" select="."/>
      <!-- handle special RSdoc:Sibling 
        note that we will not exempt RDLDocumenter from this treatment, if you want
        to document certain attributes that are allowed to CustomReportItems among other
        types, RDLDocumenter will be documented like all others
      -->
      <xsl:variable name="xmlRSDocSibling" select="$thisNode/child::*[name() = 'RSdoc:Sibling']"/>
      <xsl:if test="$xmlRSDocSibling">
         <xsl:for-each select="$xmlRSDocSibling">
            <xsl:variable name="thisItem" select="./*[local-name() = 'Item']/text()"/>
            <xsl:variable name="thisLabel" select="./*[local-name() = 'Label']/text()"/>
            <xsl:variable name="thisSibling" select="$thisNode/*[local-name()=$thisItem]"/>
            <xsl:if test="$thisSibling">
               <xsl:call-template name="DocRow">
                  <xsl:with-param name="thisTag" select="$thisLabel"/>
                  <xsl:with-param name="thisValue" select="$thisSibling/text()"/>
                  <xsl:with-param name="thisRDLLayoutType" select="local-name($thisNode)"/>
                  <xsl:with-param name="thisRDLLayoutName" select="$thisNode/@Name"/>
                  <xsl:with-param name="thisRDLLayoutParentTag" select="local-name($thisNode/..)"/>
                  <xsl:with-param name="thisRDLLayoutParentName" select="$thisNode/../@Name"/>
               </xsl:call-template>
            </xsl:if>
         </xsl:for-each>
      </xsl:if>
   </xsl:template>

   <xsl:template match="*" mode="meta-children">
      <xsl:variable name="thisParentNode" select="."/>
      <!-- handle special RSdoc:Children nodes in this item to apply to its descendants 
        note that we will not exempt RDLDocumenter from this treatment, if you want
        to document CustomReportItems it will be documented like all others -->
      <xsl:variable name="xmlRSDocChildren" select="$thisParentNode/child::*[name() = 'RSdoc:Children']"/>
      <xsl:if test="$xmlRSDocChildren">
         <xsl:for-each select="$xmlRSDocChildren">
            <xsl:variable name="thisItem" select="./*[local-name() = 'Item']/text()"/>
            <xsl:for-each select="$thisParentNode/descendant::*[local-name()=$thisItem]">
               <xsl:variable name="thisChild" select=".."/>
               <xsl:call-template name="DocRow">
                  <xsl:with-param name="thisTag" select="$thisItem"/>
                  <xsl:with-param name="thisValue" select="./text()"/>
                  <xsl:with-param name="thisRDLLayoutType" select="local-name($thisChild/..)"/>
                  <xsl:with-param name="thisRDLLayoutName" select="$thisChild/../@Name"/>
                  <xsl:with-param name="thisRDLLayoutParentTag" select="local-name($thisParentNode)"/>
                  <xsl:with-param name="thisRDLLayoutParentName" select="$thisParentNode/@Name"/>
               </xsl:call-template>
            </xsl:for-each>
         </xsl:for-each>
      </xsl:if>
   </xsl:template>

<xsl:template match="@xmlns">
	
</xsl:template>
</xsl:stylesheet>