http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1404 *** shadow/1404 Sun May 20 17:25:35 2001 --- shadow/1404.tmp.10687 Sun Jun 24 09:38:13 2001 *************** *** 1,19 **** ! Bug#: 1404 ! Product: XalanJ2 ! Version: 2.0.0 ! Platform: Sun ! OS/Version: Solaris ! Status: NEW ! Resolution: ! Severity: Normal ! Priority: Medium ! Component: org.apache.xalan.xsltc ! AssignedTo: [EMAIL PROTECTED] ! ReportedBy: [EMAIL PROTECTED] ! URL: ! Cc: ! Summary: relative paths in include/imports cause problems ! [taken from SunMicrosystem's bugs 4416429 and 4420707] According to the spec the current working directory should change depending on the path in an include/import. But once a relative path is encountered in --- 1,19 ---- ! +============================================================================+ ! | relative paths in include/imports cause problems | ! +----------------------------------------------------------------------------+ ! | Bug #: 1404 Product: XalanJ2 | ! | Status: NEW Version: 2.0.0 | ! | Resolution: Platform: Sun | ! | Severity: Normal OS/Version: Solaris | ! | Priority: Medium Component: org.apache.xalan.xsltc | ! +----------------------------------------------------------------------------+ ! | Assigned To: [EMAIL PROTECTED] | ! | Reported By: [EMAIL PROTECTED] | ! | CC list: Cc: | ! +----------------------------------------------------------------------------+ ! | URL: | ! +============================================================================+ ! | DESCRIPTION | [taken from SunMicrosystem's bugs 4416429 and 4420707] According to the spec the current working directory should change depending on the path in an include/import. But once a relative path is encountered in *************** *** 135,137 **** --- 135,195 ---- <xsl:import href="dummyb.xsl"/> <xsl:import href="dummyc.xsl"/> </xsl:transform> + + ------- Additional Comments From [EMAIL PROTECTED] 2001-06-24 09:38 ------- + Disclaimer: Using nwalsh'es docbook XSL stylesheets version 1.29 + + It seems the relative path problems only occur when there is an exception while + processing the imported or included stylesheet. + Putting the code that restores the correct current stylesheet in a finally + clause makes the problem go away. See below. + + Incidentally, I had problems with these stylesheets because some imported + stylesheets use literal XML at top-level, so an extra check of "if (next + instanceof TopLevelElement)" was needed to avoid ClassCastExceptions for QName + (literal elements) objects. + + + + public void parseContents(Element element, final Parser parser) { + final Stylesheet context = parser.getCurrentStylesheet(); + try { + final String href = element.getAttribute("href"); + final URL toImport = new URL(context.getURL(), href); + if (context.checkForLoop(toImport)) + throw new Exception(toImport.toString() + " already loaded"); + + final Element stylesheetEl = parser.parse(toImport); + if (stylesheetEl == null) return; + final Stylesheet _imported = parser.makeStylesheet(stylesheetEl); + if (_imported == null) return; + + _imported.setURL(toImport); + _imported.setParentStylesheet(context); + + // precedence for the including stylesheet + final int currPrecedence = parser.getCurrentImportPrecedence(); + final int nextPrecedence = parser.getNextImportPrecedence(); + _imported.setImportPrecedence(currPrecedence); + context.setImportPrecedence(nextPrecedence); + + parser.setCurrentStylesheet(_imported); + _imported.parseContents(stylesheetEl, parser); + + final Enumeration elements = _imported.elements(); + final Stylesheet topStylesheet = parser.getTopLevelStylesheet(); + while (elements.hasMoreElements()) { + final Object next = elements.nextElement(); + if (next instanceof TopLevelElement) { + topStylesheet.addElement((TopLevelElement)next); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + finally { + parser.setCurrentStylesheet(context); + } + } +
