How to format / indent the output of an XSL transform

I am trying to output a piece of html code. But I need it to be printed / indented. Is there any way to do this without using <xsl:text>&#xa;</xsl:text>and <xsl:text>&#9;</xsl:text>?

I used the following line without any results.

<xsl:output method="html" indent="yes"/>

Follwoing is a C # code;

    XslCompiledTransform XSLT = new XslCompiledTransform();
    XSLT.Load(xslPath);

    using (XmlTextWriter writer = new XmlTextWriter(writePath, null))
    {
        if (isTopLevel)
        {
            XSLT.Transform(XMLDocumentForCurrentUser, writer);
        }
        else
        {
            XsltArgumentList xslArg = new XsltArgumentList();
            xslArg.AddParam("MenuIndex", "", menuIndex);
            XSLT.Transform(XMLDocumentForCurrentUser, xslArg, writer);
        }
    }
 // I write the output to file  
//All this works fine, only now I need the HTML to be readable (in the browser view source or any notepad)

Does anyone know a way to format (at least indent) XSLT output?

+5
source share
2 answers

Do not create your own XmlTextWriter if you want the XSLT processor to use the xsl: output directive. Instead, write directly to the file or create an XmlWriter as follows:

using (XmlWriter result = XmlWriter.Create(writePath, XSLT.OutputSettings))
{
        if (isTopLevel)
        {
            XSLT.Transform(XMLDocumentForCurrentUser, result);
        }
        else
        {
            XsltArgumentList xslArg = new XsltArgumentList();
            xslArg.AddParam("MenuIndex", "", menuIndex);
            XSLT.Transform(XMLDocumentForCurrentUser, xslArg, result);
        }
}
+6
source

All Articles