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 6613401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:12:52+00:00 2026-05-25T20:12:52+00:00

I was working on xslt on android. The users.xml file: <?xml version=1.0 encoding=utf-8?> <users>

  • 0

I was working on xslt on android.
The users.xml file:

<?xml version="1.0" encoding="utf-8"?>
<users>
  <user>
    <fname>somename</fname>
    <hobbies>
      <hobby>Movie</hobby>
      <hobby>Trekking</hobby>
    </hobbies>
  </user>
</users>

The users.xsl file

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <body>
                <xsl:for-each select="users/user">
                    <h2>
                        <xsl:value-of select="fname" />
                    </h2>
                    <h3>Hobbies :</h3>
                    <xsl:for-each select="hobbies/hobby">
                        <xsl:value-of select="." />
                        <xsl:if test="position() != last()">
                            <xsl:text> , </xsl:text>
                        </xsl:if>
                    </xsl:for-each>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

android layout userview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <WebView
        android:id="@+id/userwebview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>

Android activity

public class UserDisplayActivity extends Activity {
    WebView userView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.userwebview);
        userView = (WebView) findViewById(R.id.userwebview);
        loadTransformedHtml();
    }
    private void loadTransformedHtml() {
        try {
            String htmlTransformed=UserXmlTransform.getTransformedHtml();
            userView.loadData(htmlTransformed, "text/html", "utf-8");
        } catch (TransformerException e) {
            e.printStackTrace();
        }
    }
 }

And UserXmlTransform class

public class UserXmlTransform {
    static final String sdPath=Environment.getExternalStorageDirectory().getAbsolutePath();
    static final File xmlFileF = new File(sdPath+"/users.xml");
    static final File xsltFileF = new File(sdPath+"/users.xsl");
    public static String getTransformedHtml() throws TransformerException {
        Source srcXml = new StreamSource(xmlFileF);
        Source srcXsl = new StreamSource(xsltFileF);
        StringWriter writer = new StringWriter();
        Result result = new StreamResult(writer);
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer(srcXsl);
        transformer.transform(srcXml, result);
        return writer.toString();
    }
}

The transformation is successfully run with UserXmlTransform.java code while testing as java project with exactly same xml and xsl file.

In android app, the files are at appropriate location.
But while running the NullPointer Exception is thrown at line

transformer.transform(srcXml, result); 

of UserXmlTransform.java. why this transformer object became null in android.

I could not figure out what is problem. Please Help me.
[Added] I am using SDK 2.2

  • 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-25T20:12:52+00:00Added an answer on May 25, 2026 at 8:12 pm

    I did the following change in users.xsl :

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    

    To

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    

    And the problem was solved.

    But still don’t know why this caused the error.

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

Sidebar

Related Questions

I'm working on XSLT. I have this XML source file : <?xml version=1.0 encoding=UTF-8?>
I am working on this from xslt cookbook type my.xml <?xml version=1.0 encoding=UTF-8?> <people>
I am working with an open source version of the Saxon XSLT processor Saxon
I'm working on a XSLT file and I've hit a snag. I have a
I'm working on a XSLT transformation that consists on merging two XML and then
I'm working on an application that uses XSLT to transform XML generated by JSP.
XSLT available is 1.0. I'm working on a dual-language site in an XML-based CMS
I'm working on XSLT 1.0 version I have declared an int variable that have
I have been working on a XSLT file here. I had been writing CSS
I am working with a CV project using XML for storing CVs, using XSLT

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.