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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:33:33+00:00 2026-05-13T09:33:33+00:00

can anyone start me off with regard to converting some XML to HTML. I’ve

  • 0

can anyone start me off with regard to converting some XML to HTML. I’ve worked on XSLT conversions before, but never from scratch, and I seem to be missing something.

Starting with XML that’s something like this:

<order name="fred" value="123.45">
  <lines>
    <line description="foo" value="123"/>
    <line description="bar" value="0.45"/>
  </lines>
</order>

…and an XSLT file that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:decimal-format name="sterling" decimal-separator="." grouping-separator=","/>
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <xsl:apply-templates select="order"/>
      </head>
      <body>
        <table border="2">
          <xsl:apply-templates  select="order/lines/line"/>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="order">
    Name is '<xsl:value-of select="@name"/>' and value is <xsl:value-of select="format-number(@value, '£#,###.00', 'sterling')"/>
  </xsl:template>

  <xsl:template match="order/lines/line">
    <tr>
      <td>
        <xsl:value-of select="@description"/>
      </td>
      <td>
        <xsl:value-of select="@value"/>
      </td>
    </tr>
  </xsl:template>

</xsl:stylesheet>

When I do the conversion using an XslCompiledTransform object from C#, I get the basic html but no content for the the lines. The code I used to the the transform isas follows:

private static String GetHtml(String xml)
{
    String result;

    var doc = new XmlDocument();
    doc.LoadXml(xml);

    var transformer = new XslCompiledTransform(true);
    transformer.Load("foobar.xslt");

    using (var writer = new StringWriter())
    {
        transformer.Transform(doc, null, writer);
        result = writer.ToString();
    }

    return result;
}

Any help greatly appreciated.

Ross

(as an aside, what’s the point of the xsl:decimal-format element if, in using the format-number function, I have to provide the format string ?)

  • 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-13T09:33:33+00:00Added an answer on May 13, 2026 at 9:33 am

    This will never be used, as there is no attribute or element named fred:

    <xsl:template match="fred">
    

    You need something like:

    <xsl:template match="@name">
    

    And similarly, the apply-templates section calling this attribute needs to change to:

    <xsl:apply-templates select="@name"/>
    

    Based on the structure of the XML you posted, you need to change every mention of fred to order in your XSLT.

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

Sidebar

Related Questions

i have a input tag which is non editable, but some times i need
Can i get the source code for a WAMP stack installer somewhere? Any help
I need to solve the following question which i can't get to work by
If all tables I want to delete from have the column gamer_id can i
I'm in the process of porting some code from Linux to Mac OS X.
I want to use a temp directory that will be unique to this build.
Every time that I want to do a Layout, I'm getting a black layout
I'm trying to build a C++ extension for python using swig. I've followed the
I have a new web app that is packaged as a WAR as part
We manage a site for a medical charity. They have a number of links

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.