How do I get HTML output from XslCompiledTransform in 2.0?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I get HTML output from the new in 2.0 XslCompiledTransform?

The XslCompiledTransform class has a read only OutputMethod property. The
XslCompiledTransform.Transform() method takes an XmlWriter, which has an
XmlSettings object with a read only OutputMethod property. At runtime
XslCompiledTransform doesn't appear to honor an <xsl:output method="html"/>
tag in the supplied XSL.

Do you have any suggestions?

Thank you.
 
lwickland said:
How do I get HTML output from the new in 2.0 XslCompiledTransform?

The XslCompiledTransform class has a read only OutputMethod property. The
XslCompiledTransform.Transform() method takes an XmlWriter, which has an
XmlSettings object with a read only OutputMethod property. At runtime
XslCompiledTransform doesn't appear to honor an <xsl:output
method="html"/>
tag in the supplied XSL.

Do you have any suggestions?

Well, the simplist option is to generate xhtml. However, the Transfomr
method appears to take TextWriter and Stream as well. Maybe you need to use
a different overload?
 
Daniel,

Thanks for the suggestion. Using a Stream instead of an XmlWriter for the
last argument solvled the problem.

Leif
 
Sorry for the late answer. Let me cite the "Introducing XslCompiledTransform"
article:

Respecting xsl:output: OutputSettings property

If a client application uses a Transform overload that takes an XmlWriter as
the output object, XslCompiledTransform ignores all xsl:output settings
specified in the stylesheet. In this case the client is responsible for
output serialization. It may control serialization process by either passing
a custom implementation of XmlWriter or adjusting the properties of the
standard XmlTextWriter. If the client needs to know serialization settings
specified in the stylesheet, it may obtain them through the
XslCompiledTransform.OutputSettings property. Suppose, for example, that the
client needs to turn character checking off, but respect other xsl:output
settings. It may use the following code to achieve that:

// Load the stylesheet
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("MyStylesheet.xsl");

// Clone its output settings and turn character checking off
XmlWriterSettings ws = xslt.OutputSettings.Clone();
ws.CheckCharacters = false;

// Run the transformation with changed output settings
xslt.Transform("MyDocument.xml", XmlWriter.Create(Console.Out, ws));
 
Back
Top