Issue with transforming XML using XSLT results when value is empty RRS feed

  • Question

  • I am using XslCompiledTransform.Transform Method to apply XSLT to an xml file

    When transforming XML using XSLT results and value is empty resulting in short had tags . End tags are listed properly when value is present. 

    <test /> instead of <test> </test> , is there setting to change the behavior. 

    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Monday, January 8, 2018 5:00 PM

All replies


    You can't do some kind of conditional check and write out something different? 

    Monday, January 8, 2018 6:53 PM
  • According to, instead of generating the XML file, consider XslCompiledTransform.Transform that outputs to an intermediate XmlWriter, and provide a custom writer like this:

    public class MyWriter : XmlTextWriter
    	public MyWriter( string outputFile, Encoding encoding )
    		: base( outputFile, encoding )
    	public override void WriteEndElement()
    	public override System.Threading.Tasks.Task WriteEndElementAsync()
    		return base.WriteFullEndElementAsync();


    Adjust and extend it according to your needs, or give details.

    But "<test/>" is usually good too.

    • Edited by Viorel_MVP Monday, January 8, 2018 7:52 PM
    Monday, January 8, 2018 7:49 PM
  • Hello Sarat,

    Is there any update or any other assistance I could provide? You could mark the helpful reply as answer if the issue has been solved. And if you have any concerns, please do not hesitate to let us know.

    Thank you for your understanding and cooperation.

    Best regards,

    Neil Hu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Sunday, January 28, 2018 12:55 PM