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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:58:08+00:00 2026-05-10T23:58:08+00:00

An html template is compiled into the application as a resource. A fragment of

  • 0

An html template is compiled into the application as a resource. A fragment of the HTML template looks like:

<A href='%PANELLINK%' target='_blank'>    <IMG border='0' src='%PANELIMAGE%' style='%IMAGESTYLE%'> </A><BR> %CAPTIONTEXT% 

i like it like this because the larger resource HTML file contains styling, no-quirks mode, etc.

But as is always the case, they now want the option that the Anchor tag should be omitted if there is no link. Also if there is no caption, then the BR tag should be omitted.


Considered Technique Nº1

Given that i don’t want to have to build entire HTML fragments in C# code, i considered something like:

%ANCHORSTARTTAGPREFIX%<A href='%PANELLINK%' target='_blank'>%ANCHORSTARTTAGPOSTFIX%    <IMG border='0' src='%PANELIMAGE%' style='%IMAGESTYLE%'> %ANCHORENDTAGPREFIX%</A>%ANCHORENDTAGPOSTFIX%CAPTIONPREFIX%<BR> %CAPTIONTEXT%%CAPTIONPOSTFIX% 

with the idea that i could use the pre and postfixes to turn the HTML code into:

<!--<A href='%PANELLINK%' target='_blank'>-->    <IMG border='0' src='%PANELIMAGE%' style='%IMAGESTYLE%'> <!--</A>--><!--<BR> %CAPTIONTEXT%--> 

But that is just rediculous, plus one answerer reminds us that it wastes bandwith, and can be buggy.


Considered Technique Nº2

Wholesale replacement of tags:

%AnchorStartTag%    <IMG border='0' src='%PANELIMAGE%' style='%IMAGESTYLE%'> %AnchorEndTag%%CaptionStuff% 

and doing a find-replace to change

%AnchorStartTag% 

with

'<A href=\'foo\' target=\'blank\'' 

Considered Technique Nº3

i considered giving an ID to the important HTML elements:

<A id='anchor' href='%PANELLINK%' target='_blank'>    <IMG border='0' src='%PANELIMAGE%' style='%IMAGESTYLE%'> </A><BR id='captionBreak'> %CAPTIONTEXT% 

and then using an HTML DOM parser to programatically delete nodes. But there is no easy access to a trustworthy HTML DOM parser. If the HTML was instead xhtml i would use various built-in/nativly available xml DOM parsers.


Considered Technique Nº4

What i actually have so far is:

private const String htmlEmptyTemplate =      @'<!DOCTYPE HTML PUBLIC ''-//W3C//DTD HTML 4.01//EN\'''+Environment.NewLine+     @'   ''http://www.w3.org/TR/html4/strict.dtd''>'+Environment.NewLine+     @'<HTML>'+Environment.NewLine+     @'<HEAD>'+Environment.NewLine+     @'  <TITLE>New Document</TITLE>'+Environment.NewLine+     @'  <META http-equiv=''X-UA-Compatible'' content=''IE=edge''>'''+Environment.NewLine+     @'  <META http-equiv=''Content-Type'' content=''text/html; charset=UTF-8''>'+Environment.NewLine+     @'</HEAD>'+Environment.NewLine+     @''+Environment.NewLine+     @'<BODY style=''margin: 0 auto''>'+Environment.NewLine+     @'  <DIV style=''text-align:center;''>'+Environment.NewLine+     @'      %ContentArea%'+Environment.NewLine+     @'  </DIV>' + Environment.NewLine +     @'</BODY>' + Environment.NewLine +     @'</HTML>';  private const String htmlAnchorStartTag =      @'<A href=''%PANELLINK%'' target=''_blank''>';  //Image is forbidden from having end tag private const String htmlImageTag =      @'<IMG border=''0'' src=''%PANELIMAGE%'' style=''%IMAGESTYLE%''>';  private const String htmlCaptionArea =     @'<BR>%CAPTIONTEXT%'; 

And i already want to gouge my eyeballs out. Building HTML in code is a nightmare. It’s a nightmare to write, a nightmare to debug, and a nightmare to maintain – and it will makes things difficult on the next guy. i’m hoping for another solution – since i am the next guy.

  • 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. 2026-05-10T23:58:09+00:00Added an answer on May 10, 2026 at 11:58 pm

    What about this: Store XML as your fragment:

    <fragment type='link_img_caption'>   <link href='%PANELLINK%' />   <img src='%PANELIMAGE%' style='%IMAGESTYLE%' />   <caption text='%CAPTIONTEXT%' /> </fragment> 

    Pull it out, replace the placeholders with the ‘real’ strings (that you have carefully XML-escaped of course),

    …and use a simple XML transformation to produce HTML output:

    <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>   <xsl:output method='html' version='4.0' encoding='iso-8859-1' indent='yes'/>    <xsl:template match='/'>     <xsl:apply-templates select='fragment' />   </xsl:template>    <xsl:template match='fragment[@type = 'link_img_caption']'>     <xsl:choose>       <xsl:when test='link[@href != '']'>         <a href='{link/@href}' target='_blank'>           <img src='{img/@src}' style='{img/@style}' border='0' />         </a>       </xsl:when>       <xsl:otherwise>         <img src='{img/@src}' style='{img/@style}' border='0' />       </xsl:otherwise>     </xsl:choose>     <xsl:if test='caption[@text !='']'>       <br />       <xsl:value-of select='caption/@text' />     </xsl:if>   </xsl:template>  </xsl:stylesheet> 

    Other fragment types could be added because of the type attribute. There is much room to improve this, so look at it as an example of how it could be done.

    Output:

    <a href='%PANELLINK%' target='_blank'>   <img src='%PANELIMAGE%' style='%IMAGESTYLE%' border='0'> </a> <br> %CAPTIONTEXT% 

    and, if the link href is empty in the XML:

    <img src='%PANELIMAGE%' style='%IMAGESTYLE%' border='0'> <br> %CAPTIONTEXT% 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • 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 Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

First off, I'm new to Scala. I'm trying to make a template parser in
I am working on a group senior project for my university and I have
I have a class that I've been provided that I really don't want to
I'm working on integrating an HTML template slice into a SiteFinity theme and am

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.