Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3398402
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:38:42+00:00 2026-05-18T04:38:42+00:00

I want to transform some xml using an xsl-file and output the result somehow

  • 0

I want to transform some xml using an xsl-file and output the result somehow (I’m using Android Api Level 8).

My current activity looks like this, but the transformer stays null.
LogCat throws an System.err with org.apache.harmony.xml.ExpatParser$ParseException, saying the xml is not well-formed, but I made sure it is.

I found a hint in LogCat that says SystemId Unknown just before the above error message.

What am I doing wrong?

import java.io.OutputStream;

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import android.app.Activity;
import android.os.Bundle;

public class XsltTester extends Activity {

    private static String TAG = XsltTester.class.getSimpleName();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        try {

            Source xmlSource = new StreamSource(this.getResources().openRawResource(R.xml.source));
            Source xsltSource = new StreamSource(this.getResources().openRawResource(R.xml.products));

            TransformerFactory transFact = TransformerFactory.newInstance();
            Transformer trans = transFact.newTransformer(xsltSource);
            OutputStream output = new StringOutputStream();
            StreamResult result = new StreamResult(output);
            trans.transform(xmlSource, result);

        } catch (TransformerConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TransformerFactoryConfigurationError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TransformerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

This is the xml-file to be transformed (source.xml)

<?xml version="1.0"?>
<!-- <?xml-stylesheet href="beatle.xsl" type="text/xsl"?> -->
<person>
 <name>
  <firstname>Paul</firstname>
  <lastname>McCartney</lastname>
 </name>
 <job>Singer</job>
 <gender>Male</gender>
</person>

And this is the corresponding xsl (products.xsl)

<xsl:template match="child::person">
 <html>
  <head>
   <title>
    <xsl:value-of select="descendant::firstname" />
    <xsl:text> </xsl:text>
    <xsl:value-of select="descendant::lastname" />
   </title>
  </head>
  <body>
   <xsl:value-of select="descendant::firstname" />
   <xsl:text> </xsl:text>
   <xsl:value-of select="descendant::lastname" />
  </body>
 </html>
</xsl:template>
</xsl:stylesheet>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:38:42+00:00Added an answer on May 18, 2026 at 4:38 am

    I just found out what the problem is: I put the XML/XSLT files in res/xml not in res/raw with the result of mangled XML format.

    Much ado about nothing 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using XSLT 1.0 an want to transform an XML file. It works fine
This is my Xml file.i want to transform this xml file into another customized
i want to transform some xml into HTML that has the following format: <TR><TD>
I'm practicing some XSL and using this XML document as a simple example: <?xml
I am creating some xsl to transform my xml into text (which will be
I'm using an XsltCompiledTransform to transform some XML into a fragment of HTML (not
I want to read an xml file, apply a transform, then write to another
I have some Java objects that I want to transform to XML. Some of
I am using xsl to transform a xml to html. A table is created
I want to store some fragments of an XML file in separate files. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.