Here is the XSLT:
<xsl:stylesheet version="1.0" xmlns:P="http://abc.com/Xyz.xsd" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="Thing">
<xsl:element name="div">
<xsl:attribute name="class">
<xsl:text>Field</xsl:text>
</xsl:attribute>
<xsl:element name="span">
<xsl:attribute name="class">
<xsl:text>Label</xsl:text>
</xsl:attribute>
<xsl:value-of select="$displayName"/>
<xsl:text>:</xsl:text>
</xsl:element>
<xsl:element name="span">
<xsl:attribute name="class">
<xsl:text>Input</xsl:text>
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Here is the result of the XSLT conversion:
<div class="Field"><span class="Label">Name:</span><span class="Input"></span></div>
This is how I do the conversion:
XslCompiledTransform xslTransform = new XslCompiledTransform();
xslTransform.Load(xsltPath, new XsltSettings(true, true), new XmlUrlResolver());
using (FileStream outputStream = File.Create(outputPath))
{
using (StringReader stringReader = new StringReader(xml))
{
using (XmlReader xmlReader = XmlReader.Create(stringReader))
{
xslTransform.Transform(xmlReader, outputStream);
}
}
}
Why is the format not indented? Later in the output, some things are indented. I do not know why. I am looking for a solution that will respect the format settings as stated in XSLT. This code is used to write to any format (XML, HTML, text, etc.), so I do not want the specific code to work only with XML. But if my XSLT has XML output and is indented, then this should be done.
source
share