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 9252175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:52:43+00:00 2026-06-18T10:52:43+00:00

For some reason my below code gives the exception: javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet

  • 0

For some reason my below code gives the exception: javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet

public String removePrettyPrint(String xml) throws TransformerException, TransformerFactoryConfigurationError {
    String result = "";
    TransformerFactory factory = TransformerFactory.newInstance();
    String source = "<?xml version=\"1.0\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">    <xsl:output indent=\"no\" />    <xsl:template match=\"@*|node()\">        <xsl:copy>            <xsl:apply-templates select=\"@*|node()\"/>        </xsl:copy>    </xsl:template></xsl:stylesheet>";
    Source xslt = new StreamSource(source);
    Transformer transformer = factory.newTransformer(xslt);
    Source text = new StreamSource(xml);
    transformer.transform(text, new StreamResult(result));
    return result;
}

What is wrong with it?

  • 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-18T10:52:45+00:00Added an answer on June 18, 2026 at 10:52 am

    I think the problem is that when you pass a string as a parameter to the StreamSource, it expects it to be a URL of an XML document, not the actual XML string itself.

    You probably need to use a StringReader reader here:

    String source = "...XSL Here...";
    StringReader xsltReader = new StringReader(source);
    Source xslt = new StreamSource(xsltReader);
    Transformer transformer = factory.newTransformer(xslt);
    

    You’ll probably have to do the same for the XML, assuming you are passing in XML, and not the URL to an XML document.

    StringReader xmlReader = new StringReader(xml);
    Source text = new StreamSource(xmlReader);
    

    And for the transform itself, you may need to make use of a StringWriter

    StringWriter writer = new StringWriter();
    transformer.transform(text, new StreamResult(writer));
    result = writer.toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason the script below is not working. This is the code I
For some reason i'm getting an unexpected [ in the below line of code.
Below is the code for a simple menu in C++. For some reason, if
The below piece of code is giving me a error for some reason, Can
Below is some of my error logging code. When an exception happens inside my
In the method below titleForHeaderInSection , for some reason the NSLog prints out the
Below is the syntax I am using for the background Image. For some reason
For some weird reason, the codes below are first working, then website is redirecting
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
The code below adds totals of check boxes and gives a discount if ALL

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.