1

I'm handling a task in which .java, .xslt, .bat and .properties files are involved.

Idea: to transform an xml-based file with extension tmx into a txt file, using xslt. Java is used as a kind of medium, connecting .properties and xslt. In the properties file, some parameters are appointed.

xml=abc.tmx xsl=aaa.xsl output=bbb.txt

The bat file acts as a launcher:

java -Xms512m -Xmx768m -DentityExpansionLimit=2000000 -classpath . transformations.TMXTransform

As you can imagine I have to modify the properties file for each processing, with only one output generated, which is not ideal in terms of efficiency.

Now I'd like to have a better solution.

  1. all files in a specific location with specific extension are detected automatically, say a.tmx, b.tmx, c.tmx....z.tmx

  2. And with one double-click, corresponding txt output files with customizable filename,say a_output.txt, b_output.txt...z_output.txt) are generated to a specific location.

I suppose this is not difficult, but since I'm new to Java, I wonder if anybody can help.

BTW, directly using xslt is OK, too.

Thanks in advance.

3 Answers 3

1

Since you're not a Java wizard, I wonder whether you wouldn't be better off doing this in either Ant or XProc? Both are XML-based languages that allow you to control a sequence of transformations to selected files. It seems to me you're trying to invent a new property file syntax that's a simple control language for XSLT processing, and you don't need to, because several already exist.

Or another candidate would be xmlsh, a shellscript-like language for controlling XML processing tasks.

Sign up to request clarification or add additional context in comments.

Comments

0

Try to use the properties file in a different way. Create a custom properties file where each line represents a processing job where you specify all needed parameters. You program should read each line of the properties file, parse the parameters and process the file(s). With a single invocation your program can process as many files as you defined in your custom properties file. In order to read the properties file, use BufferedReader.readLine() and StringTokenizer or String.split() to parse the parameteres.

This is just an idea.

Comments

0

Per Michael Kay's suggestion, you could use a simple ANT build script, like this one, to transform all of your *.tmx files.

<project name="TranformXml" basedir="." default="TransformFiles">
    <target name="TransformFiles">
        <xslt basedir="${basedir}" 
            destdir="build" 
            style="transform.xsl" 
            includes="*.tmx"
            extension="_output.txt">
        </xslt>
    </target>
</project>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.