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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:43:15+00:00 2026-06-09T23:43:15+00:00

I’m taking HTML file and one XSLT file as input and generating HTML output

  • 0

I’m taking HTML file and one XSLT file as input and generating HTML output but in my folder there are multiple HTML files and I’ve to take each of them as input and generate the corresponding output file while XSLT input file remains same every time. Currently in my code I’m repeating the code block every time to take the input HTML file. Instead of this I want to iterate over all the HTML files in the folder and take them as input file one by one to generate the output. In my current code file names are also fixed like part_1.html but it can vary and in that case this code won’t work and this will create problem. Can anyone please help out in this matter:
Thanking you!

Current Java code (Sample for two files):

public void tranformation() {
        // TODO Auto-generated method stub
        transform1();
        transform2();
    }
    public static void transform1(){
        String inXML = "C:/SCORM_CP/part_1.html";
        String inXSL = "C:/source/xslt/html_new.xsl";
        String outTXT = "C:/SCORM_CP/part1_copy_copy.html";
        String renamedFile = "C:/SCORM_CP/part_1.html";
        File oldfile =new File(outTXT);
        File newfile =new File(renamedFile);
        HTML_Convert hc = new HTML_Convert();
        try {
            hc.transform(inXML,inXSL,outTXT);
            } catch(TransformerConfigurationException e) {
            System.err.println("Invalid factory configuration");
            System.err.println(e);
            } catch(TransformerException e) {
            System.err.println("Error during transformation");
            System.err.println(e);
        }
        try{
            File file = new File(inXML);
            if(file.delete()){
                System.out.println(file.getName() + " is deleted!");
                }else{
                System.out.println("Delete operation is failed.");
            }
            }catch(Exception e){
            e.printStackTrace();
        }
        if(oldfile.renameTo(newfile)){
            System.out.println("Rename succesful");
            }else{
            System.out.println("Rename failed");
        }
    }
    public static void transform2(){
        String inXML = "C:/SCORM_CP/part_2.html";
        String inXSL = "C:/source/xslt/html_new.xsl";
        String outTXT = "C:/SCORM_CP/part2_copy_copy.html";
        String renamedFile = "C:/SCORM_CP/part_2.html";
        File oldfile =new File(outTXT);
        File newfile =new File(renamedFile);
        HTML_Convert hc = new HTML_Convert();
        try {
            hc.transform(inXML,inXSL,outTXT);
            } catch(TransformerConfigurationException e) {
            System.err.println("Invalid factory configuration");
            System.err.println(e);
            } catch(TransformerException e) {
            System.err.println("Error during transformation");
            System.err.println(e);
        }
        try{
            File file = new File(inXML);
            if(file.delete()){
                System.out.println(file.getName() + " is deleted!");
                }else{
                System.out.println("Delete operation is failed.");
            }
            }catch(Exception e){
            e.printStackTrace();
        }
        if(oldfile.renameTo(newfile)){
            System.out.println("Rename succesful");
            }else{
            System.out.println("Rename failed");
        }
    }
    public void transform(String inXML,String inXSL,String outTXT)
    throws TransformerConfigurationException,
    TransformerException {
        TransformerFactory factory = TransformerFactory.newInstance();
        StreamSource xslStream = new StreamSource(inXSL);
        Transformer transformer = factory.newTransformer(xslStream);
        transformer.setErrorListener(new MyErrorListener());
        StreamSource in = new StreamSource(inXML);
        StreamResult out = new StreamResult(outTXT);
        transformer.transform(in,out);
        System.out.println("The generated XML file is:" + outTXT);
    }
}
  • 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-09T23:43:16+00:00Added an answer on June 9, 2026 at 11:43 pm

    You have to implement something like

    public class Transformation {
    
      public static void main (String[] args){
        transformation(".", ".");
      }
    
      public static void transform(String inXML, String inXSL, String outTXT, String renamedFile){
        System.out.println(inXML);
        System.out.println(inXSL);
        System.out.println(outTXT);
        System.out.println(renamedFile);
      }
    
      public static void transformation(String inFolder, String outFolder){
        File infolder = new File(inFolder);
        File outfolder = new File(outFolder);
        if (infolder.isDirectory() && outfolder.isDirectory()){
          System.out.println("In " + infolder.getAbsolutePath());
          System.out.println("Out " + outfolder.getAbsolutePath());
          File[] listOfFiles = infolder.listFiles();
          String outPath = outfolder.getAbsolutePath();
          String inPath = infolder.getAbsolutePath();
          for (File f: listOfFiles) {
            if (f.isFile() ) {
              System.out.println("File " + f.getName());
              int indDot = f.getName().lastIndexOf(".");
              String name = f.getName().substring(0, indDot);
              String ext = f.getName().substring(indDot+1);
              if (ext != null && ext.equals("html")){
                transform(f.getAbsolutePath(), inPath+File.separator+name+".xsl", outPath+File.separator+name+".txt", outPath+File.separator+name+".html");
    
              }
            }
          }       
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.