Search code examples
firefoxxslt-2.0xslt-grouping

XSLTProcessor returns 0x80600004 (NS_ERROR_XSLT_EXECUTION_FAILURE)


I've got the following HTML doc trying to transform some xml:

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <meta charset="utf-8"/>
        <script>
            var rawXml = `<?xml version="1.0" encoding="UTF-8"?>
            <songs>
                <song name="She loves you" artist="Beatles"/>
                <song name="Yesterday" artist="Beatles "/>
                <song name="Satisfaction" artist="Rolling Stones"/>
                <song name="My Generation" artist="Who"/>
                <song name="Under My Thumb" artist="Rolling Stones"/>
            </songs>`;
            
            var rawXsl = `<?xml version="1.0" encoding="UTF-8"?>
            <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                <xsl:template match="/">
                    <table>
                        <tr>
                            <th>Artist</th>
                            <th>Song list</th>
                        </tr>
                        <!-- <xsl:for-each select="songs/song"> -->
                            <!-- <tr> -->
                                <!-- <td><xsl:value-of select="@artist"/></td> -->
                                <!-- <td><xsl:value-of select="@name"/></td> -->
                            <!-- </tr> -->
                        <!-- </xsl:for-each> -->
                        <xsl:for-each-group select="songs/song" group-by="@artist">
                            <tr>
                                <td><xsl:value-of select="current-grouping-key()"/></td>
                                <td><xsl:value-of select="current-group()/@name" separator=","/></td>
                            </tr>
                        </xsl:for-each-group>
                    </table>
                </xsl:template>
            </xsl:stylesheet>`;
            
            function parseXml(text)
            {
                var parser = new DOMParser();
                var xml = parser.parseFromString(text, "application/xml");
                return xml;
            }

            function displayContent()
            {
                var xml = parseXml(rawXml);
                var xsl = parseXml(rawXsl);
                
                var xsltProcessor = new XSLTProcessor();
                xsltProcessor.importStylesheet(xsl);
                var resultDocument = xsltProcessor.transformToFragment(xml, document);
                var target = document.getElementById("contentTarget");
                target.appendChild(resultDocument);
            }
        </script>
    </head>
    <body onload="displayContent()">
        <div id="contentTarget"></div>
    </body>
</html>

So in firefox I get said error 0x80600004 (NS_ERROR_XSLT_EXECUTION_FAILURE) and TBH, I have no idea why. I also tried it in Edge Chromium, there I just see the table header and apparently execution stops when trying to group, but I'm not able to make edge report any error.

If you comment in the xsl:for-each and comment out xsl:for-each-group, it works perfectly fine. What am I doing wrong, when trying to group?


Solution

  • The answer is simple:
    ALL Browsers (unfortunately) only support XSLT-1.0. But the for-each-group instruction is part of XSLT-2.0. So if you use it, the stylesheet will not work (See Grouping With XSLT 2.0).

    Solution:
    Stick to XSLT-1.0 instructions and complain vigorously to the browser creators.