3

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=\"*\" />"
1
  • 1
    For info - it is much easier to keep your xslt in either files or resx; writing xslt inside C# strings is just painful. Commented May 27, 2009 at 9:32

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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...
No, an unclosed img element is never valid in xhtml; it must be either <img.../> or <img...>...</img>
An unclosed anything is invalid - it's just that empty elements have two ways to implement closure.
That was sensible answer .. so +1
1

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.

2 Comments

CDATA won't render the tag out though, it'll be rendered as "&lt;img src='...'&gt;"
Good point. I now remember doing something very dodgy with output-escaping to get around that, but I clearly blocked that out.
0

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

1 Comment

fwiw, xhtml output is produced by output="xml" with appropriate doctype-system and doctype-public attributes to fix the type
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.