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%">'>
]>
...
<td>&bullet;</td>
...

> 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>
>     <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH=100%>
>     <TR BGCOLOR=pColor><TD WIDTH=4%><A HREF="mailto:pEmail">
>        <IMG VALIGN=ABSMIDDLE BORDER=0
> 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="bill_clinton@wh.com"
> 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="bill_clinton@whitehouse.gov"
name="Clinton, Bill" city="Washington"/>

in the document instance, and then in the stylesheet:

<rule>
  <!-- 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:"+element.email()'>
        <image source="images/mail.gif"/>
      </link>
    </table-cell>
    <table-cell width="32%">
      <link destination='="display.cgi?ee="+element.idno()'>
        <span weight="bold">
          <text string="=element.name()"/>
        </span>
        <text> </text>
      </link>
      <image src="images/redcross.gif"/>
    </table-cell>
    <table-cell width="22%">
      <text>202 555-1212</text>
    </table-cell>
    <table-cell width="22%"/>
    <table-cell width="20%">
      <text string="=element.city()"/>
    </table-cell>
  </table-row>
</rule>

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;
element.foo() returns the value of the foo attribute on the matched
element.

-Chris
-- 
<!NOTATION SGML.Geek PUBLIC "-//Anonymous//NOTATION SGML Geek//EN">
<!ENTITY crism PUBLIC "-//O'Reilly//NONSGML Christopher R. Maden//EN"
"<URL>http://www.oreilly.com/people/staff/crism/ <TEL>+1.617.499.7487
<USMAIL>90 Sherman Street, Cambridge, MA 02140 USA" NDATA SGML.Geek>

Received on Friday, 19 December 1997 15:54:28 UTC