Reputation: 2563
The problem is, that my XSLT-Transformation process ( called by .NET ), doesn't leave the HTML content in the XSLT file alone ( which isn't xml-compliant like an <img>
tag without an closing slash-sign ), so i'll get errors like:
<pre>System.Xml.Xsl.XslLoadException: XSLT-Compilererror. ---> System.Xml.XmlException:
The 'img'-Starttag in Line XY does'nt match with the Endtag of 'td'.</pre>
How can I prevent this?
I would like the XSLT-processor either to ignore all the content which is no "" element or just get it to recognize the valid html-tags..
My XSL-Header looks like this ( copied from C#, so imagine the additional " are not there ):
"<xsl:stylesheet version=\"2.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" " +
"xmlns:html=\"http://www.w3.org/1999/xhtml\" xmlns=\"http://www.w3.org/1999/xhtml\" " +
"exclude-result-prefixes=\"html\">" +
"<xsl:output method=\"xhtml\" omit-xml-declaration=\"yes\" indent=\"yes\"/>" +
"<xsl:preserve-space elements=\"*\" />"
Upvotes: 3
Views: 2814
Reputation: 21742
XHTML is as the name X implies XML img tags or any other none closed tags is not XHTML-strict compliant. However to easy transition from HTML to XHTML several levels of "strict"-ness is available, some of them not being XML compliant.
if you rewrite your HTML to XHTML-strict you will have no problem
Upvotes: 0
Reputation: 1062745
What do you want to output? html or xhtml? You always write the xslt as valid xml:
<img src="somepath" ... />
or
<img src="somepath{withvalues}" ... />
But you use the xsl:output
to control it; if you want html (i.e. ) then you would use:
<xsl:output method="html" ... />
(note no "x" in the above) - or:
<xsl:output method="xml" ... />
AFAIK, "xhtml" is not a valid option for xsl:output/@method
, since it is already covered by "xml". You should also note the subtle default behaviour if you don't specify an xsl:output/@method
depends on the top element (i.e. whether it starts <html>...</html>
or not).
Upvotes: 0
Reputation: 5902
You either have to make the HTML inside the XSLT XML-compliant (which is still valid HTML), or if you really have to have the HTML be not XML-compliant, encapsulate the html in a CDATA block.
For instance:
<xsl:template .... >
<![CDATA[
<img src='...' >
]]>
</xsl:template>
Note that this is very ugly, and you would probably be better off making your HTML XML-compliant.
Upvotes: 1
Reputation: 75794
AFAIK there is no way around this. XSLT is an implementation of XML and the content of an XSLT document must respect XML standards to compile.
Fix your HTML to XHTML formatting.
Upvotes: 2