Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8761897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:23:37+00:00 2026-06-13T15:23:37+00:00

I am having a problem where one XSLT file imports another, causing my application

  • 0

I am having a problem where one XSLT file imports another, causing my application to throw a MalformedURLException. The import statement in main.xsl looks like this:

<xsl:import href="transformCommon.xsl"/>

the file transformCommon.xsl is in the same folder as main.xsl. The code that attemts to load it looks like this:

private void loadXSLTFiles(String xsltFile)
{
    TransformerFactory transformFactory = TransformerFactory.newInstance();  

    //tell the location of all of import file 
    transformFactory.setURIResolver(new ClassPathURIResolver());

    Templates cache=null;

    //cache XSLT source file for transformation reuse
    InputStream is = this.getClass().getClassLoader().getResourceAsStream(xsltFile);
    javax.xml.transform.Source xsltSource = new javax.xml.transform.stream.StreamSource(is);

    try
    {
        cache = transformFactory.newTemplates(xsltSource);
    }
    catch (TransformerConfigurationException domException)
    {
        LOG.logError("XSLT initialization error has occurred: " + domException.getMessage());
    }
    ...

The stack trace is:

Caused by: java.net.MalformedURLException
    at java.net.URL.(URL.java:602)
    at java.net.URL.(URL.java:465)
    at java.net.URL.(URL.java:414)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.xalan.templates.StylesheetRootProxy.(Unknown Source)
    ... 59 more

I’m not sure why I get this error. When I remove the import from main.xsl, everything works fine. Of course, removing it is not an option as the whole point of this was to move common functions to a separate XSLT.

What’s also interesting is that only my workstation seems to have this problem. The developer who initially wrote this code says he has no problems with it. I’m using RAD 7.5. Does anyone know how this problem could come up, on a workstation-by-workstation basis?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:23:38+00:00Added an answer on June 13, 2026 at 3:23 pm

    In order to be able to resolve relative URLs in the stylesheet (including imports) the Source from which you create the Templates needs to have a “system ID” (i.e. the URL of the .xsl file).

    Instead of

    //tell the location of all of import file 
    transformFactory.setURIResolver(new ClassPathURIResolver());
    
    //cache XSLT source file for transformation reuse
    InputStream is = this.getClass().getClassLoader().getResourceAsStream(xsltFile);
    javax.xml.transform.Source xsltSource = new javax.xml.transform.stream.StreamSource(is);
    

    try this:

    URL xsltURL = this.getClass().getClassLoader().getResource(xsltFile);
    Source xsltSource = new StreamSource(xsltURL.openStream(),
                                         xsltURL.toExternalForm());
    

    (openStream can throw IOException so you’ll either need to add that to your throws or wrap the whole thing in a try/catch).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having this problem with one of my cakePHP applications. My application displays
I am having problem with ViewDidLoad Method.I have one .Xib File in my app
I'm new to HP-UX system and having one problem with running a make file.
i'm having one problem with the javascript code. i set the minimum post file
I am having one problem with the PHP json_encode function. It encodes numbers as
I'm having a problem with one of my functions within a template class. template
hi forum member I am having one problem with setting the radiofield in the
I'm creating shopping cart and I'm having one problem: When someone orders an item
I'm very new to Python development, and am having a problem with one of
I am having a problem like this one: http://svn.haxx.se/tsvnusers/archive-2008-07/1051.shtml Except that the app is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.