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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:59:08+00:00 2026-05-11T21:59:08+00:00

I intend to implement Martin Fowler’s Two-Step View Pattern for rendering HTML in a

  • 0

I intend to implement Martin Fowler’s Two-Step View Pattern
for rendering HTML in a web application I’m writing. The general idea is that rather than having the application output raw HTML, it outputs an custom intermediary XML which is then converted to HTML/CSS. This has a number of advantages including reduced code duplication and a more consistent output.

The approach suggested by Fowler for converting the XML to the final HTML is to use XSLT.

I’ve used XSLT before and I know the basics. However, I’m wondering what are the advantages of using XSLT. An alternative approach I’m considering looks like this:

Here is an example XML output of the first rendering step:

<grid>
   <headingRow>
      <cell>Product</cell>
      <cell>Price</cell>
   </headingRow>
   <row>
      <cell>A product</cell>
      <cell type="price">$54.95</cell>
   </row>
</grid>

And the desired final HTML output:

<table class="grid">
  <tr>
    <th>Product</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>A product</td>
    <td>
      <span class="currency_symbol">$</span>
      <span class="decimal_number">54.95</span>
    </td>
  </tr>
</table>

The approach I’m considering would have one object for each tag.

class GridTag extends Tag {
  ...
  public void render() {
    System.out.println("<table class=\"grid\">");
    foreach(Tag child: children) {
      child.render();
    }
    System.out.println("</table>");
  }
  ...
}

The objects would constructed into a tree by parsing the XML. The render() method would be call on the root node. I particularly like this approach because it allows me to do cool things. Particularly, if I have a cell tag as above of with the attribute type=”price”:

<cell type="price">$54.95</price>

It’s associated Tag class could parse the contents of the tag to separate the currency symbol and the numerical value into separate HTML tags to allow the alignment of the currency symbol and the decimal point, as in the HTML output above.

<td>
  <span class="currency_symbol">$</span>
  <span class="decimal_number">54.95</span>
</td>

Questions:

Should I do this or should I use XSLT?
What are the advantages of using XSLT that I might miss out on?
If I should use XSLT, how would I go about parsing the contents of the price tag?

  • 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-11T21:59:08+00:00Added an answer on May 11, 2026 at 9:59 pm

    I can’t really say much about why you should go with the one or the other.

    I think it hugely depends on the technical details of your rendering process, whether you want it to happen on the server or on the browser, how comfortable you are with XSLT or, respectively, the alternative to XSLT.

    One point for XSLT is certainly that it is virtually impossible to generate XML output that is not well-formed (I’m not speaking of valid). It is easy to miss something when writing out strings.

    Regarding your parsing problem: Without any doubt the best way is to have data and format separated right in the XML. XSLT is not for parsing, so I don’t see why your XML can’t be in this format from the start:

    <cell type="price" symbol="$">54.95</cell>
    

    However, assuming you can’t do anything about it, this XSLT would take care of it.

    <xsl:template match="cell[@type='price']">
      <td>
        <xsl:variable name="vNonNumbers" select="translate(., '0123456789.', '')" />
        <xsl:variable name="vTheNumbers" select="translate(., $vNonNumbers, '')" />
        <span class="currency_symbol">
          <xsl:value-of select="$vNonNumbers" />
        </span>
        <span class="decimal_number">
          <xsl:value-of select="$vTheNumbers" />
        </span>
      </td>
    </xsl:template>
    

    I hope you can see why the above is essentially bad code. Compare to the alternative (if your XML would separate data and format):

    <xsl:template match="cell[@type='price']">
      <td>
        <span class="currency_symbol">
          <xsl:value-of select="@symbol" />
        </span>
        <span class="decimal_number">
          <xsl:value-of select="." />
        </span>
      </td>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's a string tokenizer for Oracle that's a little more… May 12, 2026 at 1:08 am
  • Editorial Team
    Editorial Team added an answer There are two easy tricks for deployment to your "live"… May 12, 2026 at 1:08 am
  • Editorial Team
    Editorial Team added an answer Your code has two potential locations for where one may… May 12, 2026 at 1:08 am

Related Questions

I intend to implement Martin Fowler's Two-Step View Pattern for rendering HTML in a
How to implement a web page that scales when the browser window is resized?
I'm currently working on a project which will support multiple file writing specifications (imagine
I wish to implement my software on a shareware basis, so that the user
After I've seen this PDC session I wanted to try to learn a bit

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.