Apps can't transform xml+xsl(with exslt) to html

aforum

Lurker
Hi guys, I am developing an app which loads a xml and a xsl and loads the resulting html, displaying it on the screen. It works perfectly when the xsl does not have exslt functions. However, when it does contain exslt functions, it doesn't work.

The code is rather small, so I'm posting it here:

Code:
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        
        super.onCreate(savedInstanceState);
        WebView webview = new WebView(this);
        setContentView(webview);

        Source xmlSource = new StreamSource(this.getResources().openRawResource(R.raw.xml2));
        Source xsltSource = new StreamSource(this.getResources().openRawResource(R.raw.xsl2));
        
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = null;
        ByteArrayOutputStream output = null;
        StreamResult result;
        
        try 
        {
            transformer = tFactory.newTransformer(xsltSource);
            output = new ByteArrayOutputStream();
            result = new StreamResult(output);
            transformer.transform(xmlSource, result);
            
        } catch (TransformerException e) 
        {
            e.printStackTrace();
        }
        
        ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
        
        
        String html = new Scanner(input,"UTF-8").useDelimiter("\\A").next();
        
        webview.loadData(html, "text/html", "UTF-8");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
I have attached a zip file containing 5 files: xml,xsl, xml2,xsl2, logcat.
I get the errors with xml2 and xsl2.

Please help me, I've been trying to make it work for hours...I've tried many stuff, different codes...but it doesn't seem to have anything to do with my code.

Thank you for your time.
 

Attachments

  • files.zip
    3.2 KB · Views: 37

aforum

Lurker
Thread starter
I forgot to mention 2 things: I'm using the eclipse IDE, ADT bundle thing. In addition, I have tried an equivalent code in netbeans:

Code:
public class JavaApplication4 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws TransformerConfigurationException, TransformerException, FileNotFoundException {
       Source xmlSource = new StreamSource("xml2.xml");
       Source xsltSource = new StreamSource("xsl2.xsl");
       
       TransformerFactory tFactory = TransformerFactory.newInstance();
       Transformer transformer = tFactory.newTransformer(xsltSource);
       
       ByteArrayOutputStream output = new ByteArrayOutputStream();
       StreamResult result = new StreamResult(output);
       transformer.transform(xmlSource, result);
       
       ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
       String html = new Scanner(input,"UTF-8").useDelimiter("\\A").next();
       
       System.out.println(html);
    }
}

which, to my surprise, works for both xml and xsl.
 
Top