Re: C style macros in HTML

Chris Maden (
Fri, 19 Dec 1997 15:58:58 -0500

Date: Fri, 19 Dec 1997 15:58:58 -0500
Message-Id: <>
From: Chris Maden <>
In-reply-to: <> (message from Joe Rice on Fri, 19
Subject: Re: C style macros in HTML

[Joe Rice]
> It seems to me that C style macros in HTML could dramatically reduce
> the size of many web pages.  For instance, when a graphic is used
> over and over again with particular alignment and size attributes, a
> "macro" tag could help enormously.  Or think of all the huge tables
> where every row is 95% the same.  Just look at the output of a
> search of the w3c mailing list archives for an example.  I can't
> imagine that a macro expansion facility would be very hard for
> browsers to implement.  It might be a bit tricky for some of the
> WYSIWYG editors but even there it could prove a boon.  And I believe
> it would actually simplify the coding of the "back end" of most
> CGIs.
> Below are some examples that I've cooked up.  I'm sure there are all
> sorts of problems with the particulars of the syntax I've chosen but
> this is really just for illustration.  In this example the <XM> tag
> loosely stands for "expand macro".
> A simple example (without parameters):
> <HEAD>
>  <MACRO name=bullet>
>   <img border=0 height=12 width=15
> src="/home/rice/catalog/images/star3.gif" alt="78%">
>  </MACRO>
> </HEAD>
> ...
> <TD>
>  <XM name=bullet>
> </TD>
> ...

This kind of simple example can be served by SGML general entities.
HTML does not support these, but if an extension is to be made, why
not use an existing, standardized mechanism?  You will be able to do
this in XML.

<!DOCTYPE html [
<!ENTITY bullet '<img border=0 height=12 width=15
  src="/home/rice/catalog/images/star3.gif" alt="78%">'>

> Or a more complicated example (which represents a single row
> generated by a search engine I sometimes use):
> <HEAD>
>  <MACRO name=row attrs=pColor,pName,pEmail,pCity>
>     <TR BGCOLOR=pColor><TD WIDTH=4%><A HREF="mailto:pEmail">
> SRC="images/mail.gif"></A>&nbsp;</TD>
>        <TD WIDTH=32%><A HREF="display.cgi?ee=pEmployeeNum"
>            onMouseOver="window.status='View detailed information';
> return true;">
>           <B>pName</B></A>&nbsp;<IMG VALIGN=ABSMIDDLE BORDER=0
> SRC="images/redcross.gif"></TD>
>     <TD WIDTH=22%>555 555-1212</B></TD>
>     <TD WIDTH=22%>&nbsp;</TD>
>     <TD WIDTH=20%>pCity</TD>
>     </TR>
>     </TABLE>
>  </MACRO>
> </HEAD>
> ...
> <XM name=row pColor=#d2d2d2 pEmail=""
> pName="Clinton, Bill" pCity=Washington>
> ...

The first problem here is that you can not have arbitrary attributes
on an element.  This is why <applet> uses <param name="name1"
value="value1"> subelements, instead of just <applet name1="value1">.

There isn't a way in SGML to have both a fixed DTD or tagset (which
HTML is), *and* the ability to specify arbitrary data and their
handling.  However, XML and XSL will let you do this:

<employee color="#d2d2d2" idno="1" email=""
name="Clinton, Bill" city="Washington"/>

in the document instance, and then in the stylesheet:

  <!-- element to match for this rule -->
  <target-element type="employee">

  <!-- output to make for the matched element -->
  <table-row background-color="=element.color()">
    <table-cell width="4%">
      <link destination='="mailto:"'>
        <image source="images/mail.gif"/>
    <table-cell width="32%">
      <link destination='="display.cgi?ee="+element.idno()'>
        <span weight="bold">
          <text string=""/>
        <text> </text>
      <image src="images/redcross.gif"/>
    <table-cell width="22%">
      <text>202 555-1212</text>
    <table-cell width="22%"/>
    <table-cell width="20%">
      <text string=""/>

Since XSL doesn't even have a chartered working group yet, that is
only a sample syntax; attributes that start with '=' are ECMAScript/
JavaScript expressions, and I don't know JavaScript well yet, so
pardon any syntax errors.  The intentions should be clear; returns the value of the foo attribute on the matched

<!ENTITY crism PUBLIC "-//O'Reilly//NONSGML Christopher R. Maden//EN"
"<URL> <TEL>+1.617.499.7487
<USMAIL>90 Sherman Street, Cambridge, MA 02140 USA" NDATA SGML.Geek>