protected void Page_Load(object sender, EventArgs e)
    {
        var compareId   = new Guid(Request["compare"]);
        var compareToId = new Guid(Request["compareTo"]);

        var compareData   = DataFacade.GetData <IDataChanges>(d => d.ActivityId == compareId).ToList();
        var compareToData = DataFacade.GetData <IDataChanges>(d => d.ActivityId == compareToId).ToList();


        var compareReport = new XElement("CompareReport");

        var targetIds = compareData.Select(d => d.TargetId).Union(compareToData.Select(d => d.TargetId));

        Func <IEnumerable <IDataChanges>, Guid, XElement> getXml = (data, targetId) =>
                                                                   XElement.Parse(data.Where(d => d.TargetId == targetId).Select(d => d.SerializedData).FirstOrDefault()
                                                                                  ?? "<Data />");

        foreach (var targetId in targetIds)
        {
            var compareXml   = getXml(compareData, targetId);
            var compareToXml = getXml(compareToData, targetId);

            Guid?pageId = ExtractPageId(compareXml) ?? ExtractPageId(compareToXml);

            var helper = new DataTypeHelper(targetId, pageId);

            var Data = new XElement("Data", new XAttribute("caption", helper.GetCaption()));



            var attributeNames = compareXml.Attributes().Select(a => a.Name.LocalName)
                                 .Union(compareToXml.Attributes().Select(a => a.Name.LocalName))
                                 .Except(helper.GetKeyPropertyNames());

            foreach (var attributeName in attributeNames)
            {
                var compareField   = compareXml.Attribute(attributeName);
                var compareToField = compareToXml.Attribute(attributeName);

                var property = new XElement("Property",
                                            new XAttribute("Label", helper.GetFieldLabel(attributeName)),
                                            new XAttribute("Equals", helper.EqualsValueAttributes(compareField, compareToField)),
                                            new XAttribute("IsMarkup", ismarkupystify(helper.GetValue(compareField))),
                                            new XElement("Compare", stringelingify(helper.GetValue(compareField))),
                                            new XElement("CompareTo", stringelingify(helper.GetValue(compareToField)))
                                            );

                Data.Add(property);
            }

            compareReport.Add(Data);
        }

        var compareTable = new XElement("compareTable");

        var sb  = new StringBuilder();
        var xws = new XmlWriterSettings()
        {
            OmitXmlDeclaration = true
        };

        using (var writer = XmlWriter.Create(sb, xws))
        {
            var settings = new XsltSettings(false, true);

            var xslTransform = new XslCompiledTransform();
            xslTransform.Load(
                Server.MapPath(Path.Combine(Page.TemplateSourceDirectory, "compare.xslt")),
                settings,
                new XmlUrlResolver()
                );
            xslTransform.Transform(compareReport.CreateReader(), writer);
        }

        Holder.Controls.Add(new LiteralControl(sb.ToString()));

        string eventTarget = Request.Form["__EVENTTARGET"];

        if (eventTarget == "export")
        {
            var workbook  = new Workbook();
            var worksheet = new Worksheet("Sheet1")
            {
                GenerateXmlMap = true
            };
            workbook.Worksheets.Add(worksheet);
            var columns = new List <Column>()
            {
                new Column(string.Empty, typeof(string)),
                new Column(SR.GetString("Composite.Versioning.ContentVersioning", "Table.HeadingNew"), typeof(string)),
                new Column(SR.GetString("Composite.Versioning.ContentVersioning", "Table.HeadingOld"), typeof(string))
            };

            worksheet.Columns.AddRange(columns);

            foreach (var data in compareReport.Elements("Data"))
            {
                worksheet.AddRow(data.Attribute("caption").Value, string.Empty, string.Empty);

                foreach (var property in data.Elements("Property"))
                {
                    var      equals   = property.Attribute("Equals").Value == "true";
                    var      label    = property.Attribute("Label").Value;
                    var      newvalue = property.Element("Compare").Value;
                    var      oldvalue = property.Element("CompareTo").Value;
                    DateTime date;
                    if (DateTime.TryParse(newvalue, out date))
                    {
                        newvalue = date.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    if (DateTime.TryParse(oldvalue, out date))
                    {
                        oldvalue = date.ToString("yyyy-MM-dd HH:mm:ss");
                    }

                    worksheet.AddBoldRow(!equals, label, newvalue, oldvalue);
                }

                worksheet.AddRow(string.Empty, string.Empty, string.Empty);
            }

            workbook.WriteToResponse(Context, string.Format("VersioningReport-{0:yyyy-MM-dd-HH-mm}.xls", DateTime.Now));
            return;
        }
    }