/// <summary>
    /// Preliminary render action invoked before RenderContent <see cref="RenderContent"/>.
    /// </summary>
    /// <param name="printContext">The print context.</param>
    protected override void BeginRender(PublishingEngine.PrintContext printContext)
    {
      if (!string.IsNullOrEmpty(this.RenderingItem["Item Reference"]))
      {
        this.DataSource = this.RenderingItem["Item Reference"];
      }

      if (!string.IsNullOrEmpty(this.RenderingItem["Data Key"]) && printContext.Settings.Parameters.ContainsKey(this.RenderingItem["Data Key"]))
      {
        var data = printContext.Settings.Parameters[this.RenderingItem["Data Key"]].ToString();
        if (!string.IsNullOrEmpty(data))
        {
          var items = StringUtil.Split(data, '|', true);
          if (items.Count() > 1)
          {
            this.DataSources = data;
            return;
          }

          var contextItem = printContext.Database.GetItem(data);
          if (contextItem != null)
          {
            this.DataSource = contextItem.ID.ToString();
          }
        }
      }

      // Get the data item assigned to the repeater
      var dataItem = this.GetDataItem(printContext);
      if (dataItem != null)
      {
        // apply the selector to the data item
        if (!string.IsNullOrEmpty(this.RenderingItem["Item Selector"]))
        {
          var xpath = this.RenderingItem["Item Selector"];
          if (!string.IsNullOrEmpty(xpath))
          {
            var items = dataItem.Axes.SelectItems(xpath);
            if (items != null)
            {
              this.DataSources = string.Join("|", items.Select(t => t.ID.ToString()).ToArray());
            }
          }
        }
        else if (!string.IsNullOrEmpty(this.RenderingItem["Item Field"]))
        {
          // Get the number of times we need to repeat the child elements
          this.Count = dataItem[this.RenderingItem["Item Field"]];
        }
      }
    }
    /// <summary>
    /// Renders the content.
    /// </summary>
    /// <param name="printContext">The print context.</param>
    /// <param name="output">The output.</param>
    protected override void RenderContent(PublishingEngine.PrintContext printContext, System.Xml.Linq.XElement output)
    {
      if (!string.IsNullOrEmpty(this.ChildDataKeyName))
      {
        printContext.Settings.Parameters[this.ChildDataKeyName] = this.DataSource;
      }

      if (!string.IsNullOrEmpty(this.DataSources))
      {
        foreach (var dataSource in this.DataSources.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
        {
          this.DataSource = dataSource;
          if (!string.IsNullOrEmpty(this.ChildDataKeyName))
          {
            printContext.Settings.Parameters[this.ChildDataKeyName] = dataSource;
          }

          RenderChildren(printContext, output);
        }

        return;
      }

      var dataItem = this.GetDataItem(printContext);
      if (dataItem == null && !printContext.Settings.IsClient)
      {
        return;
      }

      int count;
      if (!string.IsNullOrEmpty(this.Count) && int.TryParse(this.Count, out count) && count > 0)
      {
        for (int i = 0; i < count; i++)
        {
          // Render child elements
          this.RenderChildren(printContext, output);
        }

        return;
      }

      this.RenderChildren(printContext, output);
    }