XSLT self-closing tags issue

后端 未结 12 1122
遥遥无期
遥遥无期 2020-12-08 20:19

I am using xslt to transform an xml file to html. The .net xslt engine keeps serving me self-closing tags for empty tags.

Example:

12条回答
  •  星月不相逢
    2020-12-08 20:52

    The easy way I found was creating a new XmlTextWriter class to override the method WriteEndElement, forcing the non-closing tag and pass on the serialization process as parameter.

    public class MyXmlTextWriter : XmlTextWriter
    {
        public MyXmlTextWriter(Stream stream) : base(stream, Encoding.UTF8)
        { }
        public MyXmlTextWriter(TextWriter stream) : base(stream)
        { }
    
        public override void WriteEndElement()
        {
            base.WriteFullEndElement();
        }
    }
    

提交回复
热议问题