嗨,我想在我的Android应用程序中用xsl样式表以编程方式转换xml。以编程方式在Java/Android中的撒克逊XSLT转换
这是我的变压功能:
//-----------------------------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();
}
}
和witht他的代码,我开始转变:
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);
但创建.xml文件是空的logcat引发以下错误:
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
但rg.xml存在,我可以看到它在我的外部SD卡上。我也已经将saxon.jar添加为类路径并将其插入到libs文件夹中。
任何人都知道为什么转换不起作用?
是的我正在运行6.5.5,因为这适用于我的样式表。我已经和你讨论过了[这里](http://stackoverflow.com/questions/12368937/transformation-with-saxon-6-5-5-and-xlst-does-not-work-correctly)。但目前我认为这也可能是我的路径问题,我一遍又一遍地浏览我的项目... –
[这里](http://stackoverflow.com/questions/12624325/saxon-9-xslt -transformation-results-in-nan)是新的主题,希望你能帮助我 –
发现这个链接,它描述了新的saxon9he.jar在Android中造成问题http://sourceforge.net/mailarchive/forum.php?thread_name = 4DB92660.4070302%40saxonica.com&FORUM_NAME =撒克逊帮助 –