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?