Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6236727

XSLTC never stops resolving imported stylesheets when outer stylesheet is a DOMSource

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 1.3.0
    • Component/s: xml
    • Labels:

      Backports

        Description

        I have a stylesheet, outer.xsl, that includes another stylesheet, inner.xsl,
        via the xsl:include construct. If I provide my own URIResolver and attempt
        to compile outer.xsl from a DOMSource then XSLTC loops forever, repeatedly
        resolving inner.xsl but never actually making any progress.

        -- Bug.java --
        import java.io.*;
        import javax.xml.parsers.*;
        import javax.xml.transform.*;
        import javax.xml.transform.dom.*;
        import javax.xml.transform.stream.*;
        import org.w3c.dom.*;


        public class Bug {

            private static URIResolver resolver = new URIResolver() {
        private int n = 0;
        public Source resolve(String href, String base)
        throws TransformerException
        {
        System.err.println("resolve " + href);
        if (n++ > 10) {
        System.err.println("Test failed");
        System.exit(1);
        }
        return new StreamSource(Bug.class.getResourceAsStream(href));
        }
        };

            private static Document load(InputStream in)
        throws IOException
            {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        return db.parse(in);
        } catch (Exception x) {
        throw new RuntimeException(x);
        }
            }

            public static void main(String[] args) throws Exception {

        boolean workaround = args.length > 0;

        TransformerFactory tff = TransformerFactory.newInstance();
        tff.setURIResolver(resolver);

        InputStream xin
        = new BufferedInputStream(new FileInputStream("outer.xsl"));

        Templates tt = null;
        if (workaround)
        tt = tff.newTemplates(new StreamSource(xin));
        else
        tt = tff.newTemplates(new DOMSource(load(xin)));
        Transformer tf = tt.newTransformer();

            }

        }

        -- outer.xsl --
        <s:stylesheet xmlns:s="http://www.w3.org/1999/XSL/Transform" version="1.0">
          <s:include href="inner.xsl"/>
        </s:stylesheet>

        -- inner.xsl --
        <s:stylesheet xmlns:s="http://www.w3.org/1999/XSL/Transform" version="1.0"/>


        If I use a StreamSource rather than a DOMSource to read outer.xsl then this
        problem does not occur.

        This bug is reproducible in Tiger, in 5.0u2, and in Mustang b26.

        ###@###.### 2005-03-07 04:06:07 GMT

        integrated in tag JWSDP-1_6-b08
        ###@###.### 2005-05-02 23:03:21 GMT

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                duke J. Duke (Inactive)
                Reporter:
                mr Mark Reinhold
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: