XslTransform.transform does not generate xhtml

  • Thread starter Thread starter Bob Yuan
  • Start date Start date
B

Bob Yuan

Hi, I am working on a asp.net project that takes a xml
source and use XslTransform.transform to generate a xhtml
output.

The problem with using XslTransform is that it
automatically reformats the output as HTML instead of
xhtml. For example, if the xslt file contains <img
src="..." />, the result html file is <img src="..." > and
this is not well formed xhtml.

Is there a way to prevent this aut-reformatting from
happening? I have been testing with the simplest examples:

say the xslt is:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html><body>image<img src="#" /></body></html>
</xsl:template>
</xsl:stylesheet>

The resulting html is:
<html>
<body>image<img src="#"></body>
</html>

It is perfectly fine xml, but not xhtml since the "/" is
removed.

However, if I remove "<html><body>" etc from the xslt file:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
image<img src="#" />
</xsl:template>
</xsl:stylesheet>

I do get what I want:
<?xml version="1.0" encoding="utf-8"?>
image<img src="#" />

So, something is reformatting the html output when there
is <html> tag existing. How to turn it off?


Thanks.
 
| So, something is reformatting the html output when there
| is <html> tag existing. How to turn it off?

<xsl:output method="xml" />

if you don't specify output method, it would guess. And if you have <html>
there, sets <xsl:output method="html" />

-- Altair
 
Back
Top