I am trying to output a fragment of html code. But I need it to be pretty-printed/indented.
Is there any way to do this without using <xsl:text>
</xsl:text>
and <xsl:text>	</xsl:text>
?
I have used the following line without any results.
<xsl:output method="html" indent="yes"/>
Follwoing is the 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's view source or any notepad)
Does anybody know of a way to format(atleast indent) XSLT output?
Does anybody know of a way to format (atleast indent) XSLT output? @conqenator: If you don't want to use the serialization parameter xsl:output/@indent (maybe because it's no good like in MSXSL) and you don't want to do it manualy, then there is no solution in the scope of XSLT, but because you put such restrictions.
The resulting output from the XSLT transformation is displayed in a new document window. The Output property specifies the filename for the output. If the Output property is blank, a filename is generated in your temporary directory. The file extension is based on the xsl:output element in your style sheet and can be . xml, . txt or . htm.
Open an XML document in the XML editor. Associate an XSLT style sheet with the XML document. Add an xml-stylesheet processing instruction to the XML document. For example, add the following line to the document prolog: <?xml-stylesheet type='text/xsl' href='filename.xsl'?> Add the XSLT style sheet using the Properties window.
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code The XML editor lets you associate an XSLT style sheet with an XML document, perform the transformation, and view the output. The resulting output from the XSLT transformation is displayed in a new document window. The Output property specifies the filename for the output.
Don't create your own XmlTextWriter if you want the XSLT processor to apply the xsl:output directive. Instead either write directly to a 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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With