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

  • SEARCH
  • Home
  • 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 6606073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:21:26+00:00 2026-05-25T19:21:26+00:00

I am trying to transform an xml file with xsl stylesheet into html. this

  • 0

I am trying to transform an xml file with xsl stylesheet into html.

this is the java

TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer(new StreamSource(classLoader.getResourceAsStream("driving.xsl")));
            StreamResult drivingHtml = new StreamResult(new StringWriter());
            transformer.transform(new StreamSource(classLoader.getResourceAsStream("driving.xml")), drivingHtml);
            System.out.println(drivingHtml.getWriter().toString());

this is some of the xml:

<?xml version="1.0" encoding="UTF-8"?>
<user xmlns="http://notreal.org/ns1" xmlns:poi="http://notreal2.org/ns2">
    <address type="primary">
        <street>1031 Court St.</street>
        <city>Monhegan, NY</city>
    </address>

    <address type="secondary">
        <street> Elm St.</street>
    </address>

this is the xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <head>
            <title>User</title>
            </head>
             <body>
                       <p>Detailed Addresses</p>
                       <table>
                 <th>Primary</th>
                 <th>Secondary</th>
                          <tr>
                <xsl:apply-templates select="/user/address"/>
                          </tr>
                         </table>
             </body>
         </html>
    </xsl:template>

     <xsl:template match="address">
          <td>
             <xsl:value-of select=".[@type='primary']/street" />
             <xsl:value-of select=".[@type='secondary']/street" />
          </td>
          <td>
             <xsl:value-of select=".[@type='primary']/city" />
             <xsl:value-of select=".[@type='secondary']/city" />
          </td>
     </xsl:template>
</xsl:stylesheet>

when i run that, i get “cannot compile 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-25T19:21:26+00:00Added an answer on May 25, 2026 at 7:21 pm

    Your main problem, based on the XML and XSLT code provided, is that your code doesn’t address at all the fact that the elements in the XML document are in a default namespace.

    How to process an XML document with a default namespace is a FAQ — just search the xslt and xpath tags and you’ll find numerous good answers.

    Here is one possible solution:

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:x="http://notreal.org/ns1"
     exclude-result-prefixes="x">
     <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="/*">
      <html>
        <head>
         <title>User</title>
        </head>
        <body>
          <p>Detailed Addresses</p>
           <table>
            <thead>
             <xsl:apply-templates select="x:address/@type"/>
            </thead>
            <tr>
             <xsl:apply-templates select="x:address/x:street"/>
            </tr>
            <tr>
             <xsl:apply-templates select="x:address/x:city"/>
            </tr>
           </table>
        </body>
      </html>
     </xsl:template>
    
     <xsl:template match="@type">
      <th><xsl:value-of select="."/></th>
     </xsl:template>
    
     <xsl:template match="x:address/*">
      <td><xsl:value-of select="."/></td>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on a complete and well-formed XML document that includes the XML fragment provided in the question:

    <user xmlns="http://notreal.org/ns1"
    xmlns:poi="http://notreal2.org/ns2">
        <address type="primary">
            <street>1031 Court St.</street>
            <city>Monhegan, NY</city>
        </address>
    
        <address type="secondary">
            <street>203 Elm St.</street>
            <city>Pittsburgh, PA</city>
        </address>
    </user>
    

    produces (what seems to be) the wanted, correct result:

    <html>
       <head>
          <title>User</title>
       </head>
       <body>
          <p>Detailed Addresses</p>
          <table>
             <thead>
                <th>primary</th>
                <th>secondary</th>
             </thead>
             <tr>
                <td>1031 Court St.</td>
                <td>203 Elm St.</td>
             </tr>
             <tr>
                <td>Monhegan, NY</td>
                <td>Pittsburgh, PA</td>
             </tr>
          </table>
       </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have a script automatically transform an xml file into several html
Something's screwy here. I'm trying to parse this XSL file: <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet
I am trying to develop an XSLT stylesheet which will transform an xml into
I'm trying to use XSL-stylesheets in order to transform some generated XML-data to HTML-output.
I'm trying to query an xml file using the following xslt: <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform
I have an XML file and I'm trying convert it into a (table( HTML
I'm trying to transform one XML format to another using XSL. Try as I
i'm trying to implement an xsl file to an xml doc. however when i
I'm trying to decrypt an encrypted XML file and put it into a stream
I am using lxml 2.2.8 and trying to transform some existing html files into

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.