I am currently looking for a third party library to process XSL stylesheets in Android. I know Android 2.2 has added the javax.xml.transform.TransformerFactory
, but unfortunately we need to be able to support older versions of Android.
Are there any third-party libraries available that I can use开发者_C百科 to transform XML with XSL?
I've had a look at Xalan, Saxon and XT, but from my understanding these just provide implementations of javax.xml.transform.TransformerFactory
and still require the core abstract classes.
JAXB has builtin support of xslt transformations and special Transformer interface for it.See TransformerFactory and related classes.
I had the same problem. So far I have been able to test basic XSLT transforms on Android 2.1 using an old version of Saxon. Saxon 5.5.1 appears to be the last version of Saxon before they moved to support JAXP (The stuff that is missing from Android 2.1). It is only XSLT 1.0, but seems to basically work. You will probably need to tweak the source to get it to run right. I rebuilt the Jar after the issues I had trying to get Xalan to work (Hint: Xalan does not work on Android 2.1). Mainly just changing variables to not be named enum, and getting eclipse to generate some stub methods for things added to the DOM since then.
I found some documentation that shows how to use the Saxon XSLT from OnJava.com, and used it to create a test app that did an XSLT transform generating HTML that is displayed in a WebView.
I don't have anywhere to host the Saxon Jar, but might be able to do so later.
Opera Mobile works fine with XSLT for me on my old Htc desire.
You can copy the classes straight out of Java (found them on Grepcode.com), put them into your own namespace and use them.
You'll need:
DOMSource.java FactoryFinder.java Result.java SecuritySupport.java Source.java StreamResult.java Transformer.java TransformerFactory.java
.. and you'll need to update the references in these to refer to themselves and not the ones in the javax package. I think it's about 20 minutes of work.
精彩评论