views:

1110

answers:

4

Hi,

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=\"*\" />"
+2  A: 

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.

annakata
Well, i don't unterstand this... the <img>-tag without closing slash IS XHTML1.0 compliant but messes with xml-node architecture in the same time... i mean, everbody using XSLT to generate HTML would have this problem...
David
(Clarified) Not true - see: http://www.w3.org/TR/xhtml1/#h-4.6
annakata
No, an unclosed img element is never valid in xhtml; it must be either <img.../> or <img...>...</img>
Marc Gravell
An unclosed *anything* is invalid - it's just that empty elements have two ways to implement closure.
annakata
Yeah, you're right. Thanks!
David
That was sensible answer .. so +1
infant programmer
A: 

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.

Mario Menger
CDATA won't render the tag out though, it'll be rendered as "<img src='...'>"
annakata
Good point. I now remember doing something very dodgy with output-escaping to get around that, but I clearly blocked that out.
Mario Menger
A: 

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).

Marc Gravell
fwiw, xhtml output is produced by output="xml" with appropriate doctype-system and doctype-public attributes to fix the type
annakata
A: 

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

Rune FS