Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    144
    Thanks
    11
    Thanked 7 Times in 7 Posts

    Internet Explorer XSLT transformation error in IE

    MSXML's parser is crashing on load with error:

    Reference to undefined entity 'commat'.

    @ references the popular '@' symbol.

    Following the normal XML parser directive (<?xml...), the xsl document defines a local dtd, where the entity reference is explicitly defined:

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <!DOCTYPE xsl:stylesheet [
    <!ENTITY amp "&#38;#38;">
    <!ENTITY quote "&#38;#34;">
    <!ENTITY apos "&#38;#39;">
    <!ENTITY lpar "&#38;#40;">
    <!ENTITY rpar "&#38;#41;">
    <!ENTITY plus "&#38;#43;">
    <!ENTITY gt "&#38;#62;">
    <!ENTITY commat "&#38;#64;">
    <!ENTITY verbar "&#38;#124;">
    ]>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:xh="http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">


    The transformation succeeds outside of the browser (e.g. xalan).

    Note that posting the entirety is quite impractical, as the xml file is well over 15KB, and the XSL file contains over 1000 lines on its own, plus multiple imports.

    The code uses "msxml2.DOMDocument.6.0", and the doc object is set with:
    xslDoc.async = false;
    xslDoc.resolveExternals = true;
    xslDoc.validateOnParse = false;
    xslDoc.setProperty("ProhibitDTD", false);


    Any ideas?
    Last edited by sbhmf; 03-10-2013 at 07:01 AM. Reason: Rewrote DTD entities in a manner that would display correctly

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    kudos on using XSLT, it's my 2nd favorite language.

    don't use the entity name, use the hex char code html/xml escaped char method.

    you can do a find and replace on the file data in jscript just before the transform.
    unless you're using the msxml to load from disk, in which case you'll break a lot of things like paths and contexts by switching to a string input.


    i don't recall them all now but there are several minor snags that can keep xslt from working; you may want to double check your encoding and mimetypes. I've have to output=text or xml (when i wanted html) and then replace the output with a regexp before, again, don't remember why.

    in short, it's typically (imho)a much smaller battle to let xslt do the heavy lifting and use the implementation environment to do a few string subs before or after as needed.
    Last edited by rnd me; 03-08-2013 at 06:14 PM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • Users who have thanked rnd me for this post:

    sbhmf (03-08-2013)

  • #3
    Regular Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    144
    Thanks
    11
    Thanked 7 Times in 7 Posts
    Thx rnd,

    I've last used the browser's transform processor when version 3.0 was current, and was hoping that these issues were resolved by now. Apparently not.

  • #4
    Regular Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    144
    Thanks
    11
    Thanked 7 Times in 7 Posts
    Further investigation revealed:

    The original issue was with the previously-parsed xml file. the error was eliminated when I appended to it a reference to a the same doctype.

    Now I am receiving a different error whose errorcode is -1072896679, from the xsl parser, indicating 'Unexpected end of file.' The xsl file is well-formed, as indicated in the original post.

    The code:

    function CreateDoc() {
    if (typeof ActiveXObject != "undefined") {
    return new ActiveXObject("msxml2.DOMDocument.6.0");
    }
    else if (typeof DOMParser != "undefined") {
    //return new DomParser();
    }
    }

    function View(Value) {
    /*Instantiate Doc objects:*/
    var xmlDoc = CreateDoc();
    var xslDoc = CreateDoc();

    /*Initialize Doc objects:*/
    xmlDoc.async = false;
    xmlDoc.resolveExternals = true;
    xmlDoc.validateOnParse = false;
    if (typeof ActiveXObject != "undefined") xmlDoc.setProperty("ProhibitDTD", false);
    xmlDoc.loadXML(Value);
    if (xmlDoc.parseError.errorCode != 0) {
    alert("XML error code: " + xmlDoc.parseError.errorCode + "\n\nError: " + xmlDoc.parseError.reason);
    return;
    }
    xslDoc.async = false;
    xslDoc.resolveExternals = true;
    xslDoc.validateOnParse = true;
    if (typeof ActiveXObject != "undefined") xslDoc.setProperty("ProhibitDTD", false);
    xslDoc.load("Templates/Template1_html.xsl");
    if (xslDoc.parseError.errorCode != 0) {
    window.open().document.write("XSL error code: " +xslDoc.parseError.errorCode + "<br /><br />Error: " +xslDoc.parseError.reason);
    return;
    }

    var result = Transform(xmlDoc, xslDoc); //calls another function to manage cross-browser xform

    if (result == null) {
    alert("XSLTProcessor unavailable.");
    return;
    }

    window.open().document.write(result);
    ...
    }
    Last edited by sbhmf; 03-10-2013 at 07:11 AM.

  • #5
    Regular Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    144
    Thanks
    11
    Thanked 7 Times in 7 Posts
    Testing has revealed that while the transformation succeeds on Mac, it fails on every browser on Windows.

    While I remain hopeful that I am mistaken, I have concluded that CHARACTER ENTITY REFERENCES IN XSL FILE ARE NOT SUPPORTED ON ANY BROWSER IN WINDOWS (tested on Windows 7 Ultimate).

    Yes strong words, yet upon replacing all character entity references with decimal entity references (e.g. &commat; replaced with &# 64; ) the transformation succeeded in every tested browser on both Mac and Windows.

    I would be thankful for a demonstration that proves me wrong!

    I appreciate that MSXML.DOMDocument.6.0 is quite stringent on validating DTDs, and inhibits it by default, but this matter is not applicable to the discussion at hand because the transformation was inhibited in all browsers and not exclusively IE. Also, the final code tested did not instantiate the MSXML.DOMDocument.6.0 ActiveXObject, so even in IE DTD-validation should not have been inhibited.

    Thank you all for viewing, and to rnd_me for responding. Your constructive comments are welcome via PM as well as in this thread, though more likely to reach me via PM as this thread ages and the technology evolves.

  • #6
    Regular Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    144
    Thanks
    11
    Thanked 7 Times in 7 Posts

    Microsoft Support(MSS) Resolution

    The original XHTML, XML and XSLT are all valid, and meet w3's recommendation. Xalan and others parse it successfully, yet Firefox is the only browser that does so with minor modifications.

    MSS resolution included a number of directives:
    1. The Doctype declaration at the top of the XML source file had to be removed.
    2. Entity references are not permitted - replace them with numeric references.
    3. The XHTML file MUST contain a doctype.
    4. All @Import files referenced within XML and XSLT files must contain fully qualified paths, not relative paths, to the server on which they reside.
    5. When processing the IE transformation, be aware that IE v.9+ supports document.implementation and document.implementation.createDocument, so either use if (typeof ActiveXObject != "undefined") or include a meta tag that informs your IEv9+ browser to process the document using v8: <meta http-equiv="X-UA-Compatible" content="IE=8" >

    The subject of cross-browser XSLT transformations remains challenging, and a working solution would be the subject of a great book; I would be very interested in procuring such a book if/when it ever gets published.

    Although the resolution does not meet all of my expectations it does appear to offer a working option for the current solution.

  • #7
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,387
    Thanks
    32
    Thanked 288 Times in 282 Posts
    Quote Originally Posted by sbhmf View Post
    Any ideas?
    The problem is that you're explicitly defining predefined entities, but didn't do it correctly. Per XML 1.0, Section 4.6: Predefined Entities:

    If the entities lt or amp are declared, they MUST be declared as internal entities whose replacement text is a character reference to the respective character (less-than sign or ampersand) being escaped; the double escaping is REQUIRED for these entities so that references to them produce a well-formed result.
    Thus, <!ENTITY amp "&#38;"> produces a well-formedness error. If this is fixed via <!ENTITY amp "&#38;#38;"> your document should work in IE assuming no other issues.

    Apparently, Chrome, Firefox, and Opera don't support this part of the XML 1.0 spec, and therefore those browsers magically render the document anyway. Assuming I've read the spec correctly, <!ENTITY amp "&#38;"> should be transformed into <!ENTITY amp "&"> at load time. The transformed code contains an invalid entity reference that would make the document malformed.

    Quote Originally Posted by sbhmf View Post
    <?xml version="1.0" encoding="ISO-8859-1"?>
    I'd recommend UTF-8 instead of ISO-8859-1. It includes all of the characters in Unicode and is the standard for both HTML and XML.

    Quote Originally Posted by sbhmf View Post
    xmlns:xh="http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd"
    I don't know where this came from, but the correct media type for XHTML is http://www.w3.org/1999/xhtml.

    Quote Originally Posted by sbhmf View Post
    Testing has revealed that while the transformation succeeds on Mac, it fails on every browser on Windows.

    While I remain hopeful that I am mistaken, I have concluded that CHARACTER ENTITY REFERENCES IN XSL FILE ARE NOT SUPPORTED ON ANY BROWSER IN WINDOWS (tested on Windows 7 Ultimate).

    Yes strong words, yet upon replacing all character entity references with decimal entity references (e.g. &commat; replaced with &# 64; ) the transformation succeeded in every tested browser on both Mac and Windows.

    I would be thankful for a demonstration that proves me wrong!
    I have a working document that says otherwise:

    https://patrick.dark.name/web.dev/cf...thread.289443/

    Code:
    <?xml-stylesheet type="application/xml" href="master.xslt"?>
    <title xml:lang="en-US">Demo for CodingForums.com Thread 289443</title>
    Code:
    <!DOCTYPE stylesheet [
    	<!ENTITY amp "&#x26;#x26;">
    	<!ENTITY xslt "<abbr xmlns='http://www.w3.org/1999/xhtml' title='Extensible Stylesheet Language Transformations'>XSLT</abbr>">
    	<!ENTITY p "<code xmlns='http://www.w3.org/1999/xhtml'>ENTITY</code> declarations are supported in this implementation of &xslt; 1.0.">
    ]>
    <xslt:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" version="1.0">
    	<xslt:output media-type="application/xhtml+xml"/>
    	<xslt:template match="/">
    		<html xml:lang="en-US">
    			<head>
    				<title><xslt:value-of select="title"/></title>
    				<style>
    					* { margin: 0; }
    					html { font: 16px sans-serif; }
    					p { margin: 2em; }
    					abbr { border: none; }
    				</style>
    			</head>
    			<body>
    				<p>&p;</p>
    			</body>
    		</html>
    	</xslt:template>
    </xslt:stylesheet>
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #8
    Regular Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    144
    Thanks
    11
    Thanked 7 Times in 7 Posts
    Thank you for great comments, I concur.

    During testing, the amp was commented out and the transformation still failed.

    The MS support engineer also asserted that a DTD in the xml source file will inhibit IE from transforming it, contrary to Microsoft's own docs on MSDN.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •