1

Hi there I want to programmatically transform a xml with a xsl stylesheet in my Android application.

This is my transformer function:

//-----------------------------XLST SAXON TRANSFORMATION--------------------
public static void simpleTransform(String sourcePath, String xsltPath,
        String resultDir) {
        TransformerFactory tFactory = TransformerFactory.newInstance();
        try {
            Transformer transformer =
                    tFactory.newTransformer(new StreamSource(new File(xsltPath)));

            transformer.transform(new StreamSource(new File(sourcePath)),
    new StreamResult(new File(resultDir)));
        } catch (Exception e) {
            e.printStackTrace();
        }
}

and witht his code I start the transformation:

           private static String sourcePath;
           private static String xsltPath = SD_CARD_PATH +"/"+ "ets4_calimero_gui.xsl";
           private static String resultDir;

           sourcePath = SD_CARD_PATH + "/"+Name+".xml"; 
           resultDir = SD_CARD_PATH + "/"+Name+"_xlst.xml";

           System.setProperty("javax.xml.transform.TransformerFactory",
                "net.sf.saxon.TransformerFactoryImpl");
           simpleTransform(sourcePath, xsltPath, resultDir);
           Log.d("XLST","XML saved as" + resultDir);

but the created .xml file is empty and logcat throws the following error:

09-27 13:44:41.940: W/System.err(7736): (Location of error unknown)java.io.IOException: Couldn't open file:///mnt/sdcard/rg.xml

but the rg.xml exists, I can see it on my external sd card. I also have added the saxon.jar as classpath and inserted it in the libs folder.

Anyone a idea why the Transformation is not working?

2 Answers 2

1

You mention "saxon.jar" which makes it seem you might be running a rather old version (perhaps 6.5?). You might like to try something more recent. However, Saxon is not tested or supported on Android; we know that there are problems but we haven't done any serious work on finding out what they are and whether there might be a simple workaround (the code won't compile for Android because it has dependencies on features not present on the Android platform, and the first thing we have to do is get rid of those dependencies.)

If anyone has any experiences getting Saxon to work on Android, we'd like to hear about them.

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

3 Comments

yes I am running 6.5.5 because this works good for my Stylesheet. I already discussed this with you here. But at the moment I think it could also be a problem with my paths, I am looking through my project again and again...
HERE is the new thread, hope you can help me
Found this link which describes that the new saxon9he.jar makes problems in Android sourceforge.net/mailarchive/…
0

Android uses a lightweight XSLT parser, LibXML2, and the lightweight XSLT standard, XSLT-version-1.

For complex XSLT script (as XSLT2 specific functions) check hasExsltSupport() and use commom module of EXSLT and/or "register functions" to call Java functions from your XSLT script.

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.