How to apply an XSLT Stylesheet in C#

前端 未结 4 1663
无人及你
无人及你 2020-11-22 07:53

I want to apply an XSLT Stylesheet to an XML Document using C# and write the output to a File.

4条回答
  •  死守一世寂寞
    2020-11-22 08:24

    Based on Daren's excellent answer, note that this code can be shortened significantly by using the appropriate XslCompiledTransform.Transform overload:

    var myXslTrans = new XslCompiledTransform(); 
    myXslTrans.Load("stylesheet.xsl"); 
    myXslTrans.Transform("source.xml", "result.html"); 
    

    (Sorry for posing this as an answer, but the code block support in comments is rather limited.)

    In VB.NET, you don't even need a variable:

    With New XslCompiledTransform()
        .Load("stylesheet.xsl")
        .Transform("source.xml", "result.html")
    End With
    

提交回复
热议问题