title: When merging multiple xml files, how can I set EntityResolver for child xml files as well besides the parent xml?
body: <p>I have a book xml file which references other multiple xml files. When I try to run an xslt on the book.xml file, the EntityResolver in my code resolves the dtd path. However, for the children xml files which are being merged, the dtd paths are not resolved.</p>
  
  <h1>Sample sample_book.ditamap</h1>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE bookmap PUBLIC "-//OASIS//DTD DITA BookMap//EN" "bookmap.dtd"&gt;
  &lt;bookmap&gt;
      &lt;booktitle&gt;
          &lt;mainbooktitle&gt;sample book&lt;/mainbooktitle&gt;
      &lt;/booktitle&gt;
      &lt;part navtitle="Overview"&gt;
          &lt;topicref href="../topics/introduction.dita"/&gt;
          &lt;topicref href="../topics/install.dita"/&gt;
      &lt;/part&gt;
  &lt;/bookmap&gt;
  </code></pre>
  
  <p>`</p>
  
  <h1>Java Code</h1>
  
  <pre><code>public class XMLProcessor  {
  
         public void transform(String xmlf, String xslf) throws TransformerConfigurationException, TransformerException, org.xml.sax.SAXException, IOException{
  
          org.xml.sax.XMLReader reader = XMLReaderFactory.createXMLReader();
          Transformer transformer;
          TransformerFactory factory = TransformerFactory.newInstance();
  
           StreamSource stylesheet = new StreamSource(xslf);
  
           //Source source = StreamSource(xmlf);
           //SAXSource source = new SAXSource(new InputSource(xmlf));
          // org.xml.sax.XMLReader reader = XMLReaderFactory.createXMLReader();
  
           EntityResolver ent = new EntityResolver() {
  
              @Override
              public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
  
                  System.out.println(publicId);
                  System.out.println(systemId);
  
                  if(publicId.equals("-//OASIS//DTD DITA BookMap//EN")){
                      return new InputSource("file:///D:/sample/dtd/bookmap.dtd");
                  }
  
                  return null;
                  }
              };
          // sour.setPublicId("file:///D:/sample/dtd/bookmap/dtd/bookmap.dtd");
  
  
              reader.setEntityResolver(ent);
              SAXSource source = new SAXSource(reader, new InputSource(xmlf));
              //reader.parse(new InputSource(xmlf));
           //StreamSource sourcedoc = new StreamSource(xmlf);
           transformer = factory.newTransformer(stylesheet);
  
          try {
              transformer.transform(source, new StreamResult(new FileWriter("D:\\sample\\out\\result.xml")));
          } catch (IOException ex) {
              Logger.getLogger(XMLProcessor.class.getName()).log(Level.SEVERE, null, ex);
          }
  
      }
  
  
  
  
  
  }`
  </code></pre>
  
  <h1>Expected Result</h1>
  
  <p>`</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;pages xmlns:mf="urn:mf"&gt;
      &lt;parentpage&gt;
          &lt;parentpagename&gt;sample book&lt;/parentpagename&gt;
      &lt;/parentpage&gt;
      &lt;part&gt;
          &lt;partname&gt;Overview&lt;/partname&gt;
          &lt;text/&gt;
          &lt;level-2&gt;
              &lt;concept xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"
                  id="introduction" ditaarch:DITAArchVersion="1.3"
                  domains="(topic concept)                            (topic abbrev-d)                            a(props deliveryTarget)                            (topic equation-d)                            (topic hazard-d)                            (topic hi-d)                            (topic indexing-d)                            (topic markup-d)                            (topic mathml-d)                            (topic pr-d)                            (topic relmgmt-d)                            (topic sw-d)                            (topic svg-d)                            (topic ui-d)                            (topic ut-d)                            (topic markup-d xml-d)   "
                  class="- topic/topic concept/concept "&gt;
                  &lt;title class="- topic/title "&gt;Introduction&lt;/title&gt;
                  &lt;shortdesc class="- topic/shortdesc "/&gt;
                  &lt;conbody class="- topic/body  concept/conbody "&gt;
                      &lt;p class="- topic/p "&gt;Sample introduction&lt;/p&gt;
                  &lt;/conbody&gt;
              &lt;/concept&gt;
          &lt;/level-2&gt;
          &lt;text/&gt;
          &lt;level-2&gt;
              &lt;task xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" id="install"
                  ditaarch:DITAArchVersion="1.3"
                  domains="(topic task)                            (topic abbrev-d)                            a(props deliveryTarget)                            (topic equation-d)                            (topic hazard-d)                            (topic hi-d)                            (topic indexing-d)                            (topic markup-d)                            (topic mathml-d)                            (topic pr-d)                            (topic relmgmt-d)                            (topic sw-d)                            (topic svg-d)                            (topic ui-d)                            (topic ut-d)                            (topic markup-d xml-d)                            (topic task strictTaskbody-c)   "
                  class="- topic/topic task/task "&gt;
                  &lt;title class="- topic/title "&gt;Install&lt;/title&gt;
                  &lt;shortdesc class="- topic/shortdesc "/&gt;
                  &lt;taskbody class="- topic/body task/taskbody "&gt;
                      &lt;context class="- topic/section task/context "&gt;
                          &lt;p class="- topic/p "&gt;Download xyz installer from here. &lt;/p&gt;
                      &lt;/context&gt;
                      &lt;steps class="- topic/ol task/steps "&gt;
                          &lt;step class="- topic/li task/step "&gt;
                              &lt;cmd class="- topic/ph task/cmd "&gt;Double-click the downloader
                                  installer.&lt;/cmd&gt;
                          &lt;/step&gt;
                          &lt;step class="- topic/li task/step "&gt;
                              &lt;cmd class="- topic/ph task/cmd "&gt;Do this.&lt;/cmd&gt;
                          &lt;/step&gt;
                          &lt;step class="- topic/li task/step "&gt;
                              &lt;cmd class="- topic/ph task/cmd "&gt;Do that&lt;/cmd&gt;
                          &lt;/step&gt;
                      &lt;/steps&gt;
                  &lt;/taskbody&gt;
              &lt;/task&gt;
          &lt;/level-2&gt;
      &lt;/part&gt;
  &lt;/pages&gt;
  </code></pre>
  
  <p>`</p>
  
  <h1>Actual Result</h1>
  
  <p>When the XSLT is run, the following error message is displayed. The error goes away, when I move the dtd files to the topics folder.</p>
  
  <blockquote>
  <pre><code>Warning   XTDE0540: Ambiguous rule match for /bookmap/booktitle[1] Matches both "element(Q{}booktitle)" on line 54 of
  &gt;file:///D:/sample/xsl/merge.xsl and "element(Q{}booktitle)" on line 18 of &gt;file:///D:/sample/xsl/merge.xsl Warning at char 11 in
  </code></pre>
    
    <p>xsl:apply-templates/@select on line 30 column 104 of >merge.xsl: 
    FODC0002: I/O error reported by XML parser processing 
    file:/D:/sample/sampledoc/topics/introduction.dita: 
    D:\sample\sampledoc\topics\concept.dtd (The system cannot find the</p>
    
    <blockquote>
      <p>file specified) Warning at char 11 in xsl:apply-templates/@select on line 30 column 104 of >merge.xsl:  FODC0002: I/O error reported by
      XML parser processing  file:/D:/sample/sampledoc/topics/install.dita: 
      D:\sample\sampledoc\topics\task.dtd (The system cannot find the >file
      specified)</p>
    </blockquote>
  </blockquote>