Project

Profile

Help

Bug #4858

closed

Namespace not serialized (wrapped DOM Node)

Added by Michael Kay almost 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
DOM Interface
Sprint/Milestone:
-
Start date:
2020-12-16
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
10
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Reported today by email:

we just switched from saxon 9.9.1-7 to 10.3. We found an unexpected difference in a serialization of an element in the HTML default namespace ("http://www.w3.org/1999/xhtml"):

Consider the following fragment

1 <xsl:variable name="body" select="imf:parse-wiki(.,$value-format)" as="element(xhtml:body)"/>
2 <xsl:message select="namespace-uri($body)"/>
3 <xsl:sequence select="$body"/>

The function imf:parse-wiki() in (1) is a wrapper around an extension function, that produces a body element in the default xhtml namespace (i.e. no prefix). This is confirmed by the as-clause (no warnings/errors) as well as the statement (2) that shows http://www.w3.org/1999/xhtml in the console. However, the xsl:sequence statement in (3) produces the element without a default namespace ("

"), like:
<body xmlns:html="http://www.w3.org/1999/xhtml">
        <p>Dit type is in IMKAD gemodelleerd,......</p>
</body>

The extension function uses the DocumentWrapper() class, as per the following code:

a Node node = ((DOMSource)source).getNode();
b String baseURI = source.getSystemId();
c return = new DocumentWrapper(node.getOwnerDocument(), baseURI, configuration);

Hope this info is sufficient to pinpoint a possible flaw in 10.3 code. This issue did not exist in Saxon 9.9.1-7.

Thanks in advance!

Actions #1

Updated by Michael Kay almost 4 years ago

I've constructed this test, which shows no problems, so I'm going to need a more precise repro:

public static NodeInfo makeBodyElement(XPathContext context) throws Exception {
        String in = "<?xml version='1.0'?> \n" +
                "<body xmlns=\"http://www.w3.org/1999/xhtml\">\n"
                + "        <p>Dit type is in IMKAD gemodelleerd,......</p>\n"
                + "</body>";

        // Read an XML file to a DOM
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder db = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(in));
        Document doc = db.parse(is);
        DocumentWrapper wrapper = new DocumentWrapper(doc, "http://dummy/", context.getConfiguration());
        return wrapper.wrap(doc.getDocumentElement());
    }

    /**
     * Test that namespaces are copied OK by an identity transform
     */

    @Test
    public void testNamespaceSerialization() {
        // bug 4858
        try {
            // Stylesheet
            String xslt =
                    "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"
                            + " xmlns:my='java:jaxptest.DOMTest' xmlns:xhtml='http://www.w3.org/1999/xhtml'>\n" +
                            "  <xsl:template match='/'>\n" +
                            "    <xsl:variable name='body' as='element(xhtml:body)' select='my:makeBodyElement()'/>\n" +
                            "    <xsl:sequence select='$body'/>\n" +
                            "  </xsl:template>\n" +
                            "</xsl:stylesheet>";

            // Run a transformation that invokes an extension function returning this DOM
            TransformerFactory tFactory = new TransformerFactoryImpl();
            Templates templates = tFactory.newTemplates(new StreamSource(new StringReader(xslt)));
            Transformer transformer = templates.newTransformer();
            StringWriter sw = new StringWriter();
            transformer.transform(new StreamSource(new StringReader("<a/>")), new StreamResult(sw));
            System.err.println(sw.toString());
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }

Actions #2

Updated by Michael Kay over 3 years ago

  • Status changed from New to Closed

We haven't had any more information on this from the user, so there is no further action we can usefully take.

Please register to edit this issue

Also available in: Atom PDF