Пример #1
0
 public XElement Transform(XElement element)
 {
     using (var ms = new MemoryStream())
         using (var writer = new XHtmlWriter(new StreamWriter(ms)))
         {
             _transform.Transform(element.CreateNavigator(), writer);
             ms.Seek(0, SeekOrigin.Begin);
             return(XElement.Load(ms, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo));
         }
 }
        public static XDocument Transform(string xml, SyntaxLanguage language)
        {
            using var ms     = new MemoryStream();
            using var writer = new XHtmlWriter(new StreamWriter(ms));
            XDocument doc  = XDocument.Parse(xml, LoadOptions.PreserveWhitespace);
            var       args = new XsltArgumentList();

            args.AddParam("language", "urn:input-variables", WebUtility.HtmlEncode(language.ToString().ToLower()));
            _transform.Transform(doc.CreateNavigator(), args, writer);
            ms.Seek(0, SeekOrigin.Begin);
            return(XDocument.Load(ms, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo));
        }
Пример #3
0
        public virtual void Serialize(IEnumerable <XPathItem> items, TextWriter output, XPathSerializationOptions options)
        {
            options = options ?? new XPathSerializationOptions();

            XmlWriter writer = XmlWriter.Create(output, (XmlWriterSettings)options);

            if (options.Method == XPathSerializationMethods.XHtml)
            {
                writer = new XHtmlWriter(writer);
            }

            Serialize(items, writer);

            // NOTE: don't close writer if Serialize fails
            writer.Close();
        }
Пример #4
0
      public override void Run(XmlWriter output, XsltRuntimeOptions options) {

         if (output == null) throw new ArgumentNullException("output");
         if (options == null) throw new ArgumentNullException("options");

         if (this.possiblyXhtmlMethod || options.Serialization.Method == XmlSerializationOptions.Methods.XHtml)
            output = new XHtmlWriter(output);

         IXPathNavigable input;

         if (options.InitialContextNode != null)
            input = options.InitialContextNode;

         else
            // this processor doesn't support initial template,
            // a node must be provided
            input = this.Processor.ItemFactory.CreateNodeReadOnly();

         XsltArgumentList args = GetArguments(options);
         XmlResolver resolver = options.InputXmlResolver;

         try {
            if (CLR.IsMono) 
               monoTransform(this.transform, ((input != null) ? input.CreateNavigator() : null), args, output, resolver);
            else 
               net20Transform(this.command, input, resolver, args, output);

         } catch (XsltException ex) {
            throw new SystemXsltException(ex);
         }
      }
Пример #5
0
        public virtual void Serialize(IEnumerable<XPathItem> items, TextWriter output, XPathSerializationOptions options)
        {
            options = options ?? new XPathSerializationOptions();

             XmlWriter writer = XmlWriter.Create(output, (XmlWriterSettings)options);

             if (options.Method == XPathSerializationMethods.XHtml) {
            writer = new XHtmlWriter(writer);
             }

             Serialize(items, writer);

             // NOTE: don't close writer if Serialize fails
             writer.Close();
        }