Beispiel #1
0
        internal string generateCode(XSLTTemplate template, XSLTTemplateRepository repo)
        {
            string xslCode = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
            xslCode += "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n";

            xslCode += template.generateXSLTTemplateCode();

            foreach (XSLTTemplate xt in repo.templates)
                xslCode += xt.generateXSLTTemplateCode() + "\n";

            xslCode += "</xsl:stylesheet>\n";

            return prettyPrinter.PrintToString(xslCode);
        }
Beispiel #2
0
        private bool generateTransformationCode(XSLTTemplateRepository rep, String AbstractTreeRootElement, string fileName)
        {
            try
            {
                //check start (top most) template exists and find it
                XSLTTemplate start = null;

                foreach (XSLTTemplate x in rep.templates)
                {
                    if (String.Equals(x.TemplateName, AbstractTreeRootElement))
                    {
                        start = x;
                        break;
                    }
                }

                if (start != null)
                {

                    string xslCode = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
                    xslCode += "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n";

                    xslCode += "<xsl:template match=\"/\">\n";

                    xslCode += start.generateXSLTCall(start.TemplateName).OuterXml + "\n";

                    xslCode += "</xsl:template>\n";

                    foreach (XSLTTemplate xt in rep.templates)
                        xslCode += xt.generateXSLTTemplateCode() + "\n";

                    xslCode += "</xsl:stylesheet>\n";

                    if (!fileName.Equals(""))
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(xslCode);
                        doc.Save(fileName);
                        ReportStatusBar.ShowStatus(fileName + " Transformation saved successfully.", ReportIcon.OK);

                        //log event
                        logger.log("Transformation file \"" + fileName + "\" created.", ReportIcon.Info);

                    }
                    else
                        ReportStatusBar.ShowStatus("Unable to save transformation.", ReportIcon.Error);

                    return true;
                }

                ReportStatusBar.ShowStatus("Mapping Rule for " + AbstractTreeRootElement + " is not yet defined!", ReportIcon.Error);
            }
            catch (Exception ex)
            {
                ReportStatusBar.ShowStatus(ex.ToString(), ReportIcon.Error);
            }
            return false;
        }