WSS Home   XML/XSL Project

[Current WSSG Projects][XML project home]

Generating Dynamic HTML/XML Documents by Embedding Code

The following table briefly summarizes three commonly-used methods for generating dynamic Web pages by embedding programming code into HTML: Microsoft's Active Server Pages (ASP), Sun's Java Server Pages (JSP), and PHP.

These methods are then compared with eXtensible Server Pages (XSP), a method of generating dynamic XML documents (from which Web pages or other output formats can be then generated) by embedding programming code within XML-based structures. XSP is supported by Cocoon and AxKit, which are further described in XML-based Web Publishing Frameworks & Tools

The information in the table below is in draft form. None of the sample code below has been tested and may contain errors. There may be other errors in this document, as well.

Microsoft's Active Server Pages (ASP)

Summary
  • Comes with two scripting languages: VBScript (aka Visual Basic Scripting Edition, the default language and by far the most widely used) and JScript (Microsoft's version of ECMAScript/JavaScript)
  • Embeds scripting commands in HTML
  • Files typically named with ".asp" extension
  • Works with Microsoft's Web server, Internet Information Server (IIS), although there are third-party ports of ASP to other environments
Sample code
<%@ Language=VBScript %>
<html>
  ...
  <body>
    <% HelloVar = "Hello, world!" %>  <!-- Assign a string to a variable -->
    <%= HelloVar %>  <!-- %= outputs the value of an expression -->
    <% Response.write(HelloVar) %>  <!-- Alternate method of outputting this value -->
  </body>
</html>
      
Can separate code from HTML markup? No?
Descriptions & tutorials Tutorial: Microsoft's Active Server Pages Tutorial

Sun's JavaServer Pages (JSP)

Summary
  • Uses Java code
  • Embeds scripting commands in HTML
  • Can load and include output from Java beans
  • Creates a Java servlet with static HTML printed to the output stream
  • Files typically named with ".jsp" extension
Sample code
<%@ page info="Hello, World example" %>
<html>
  ...
  <body>
    <%! String HelloVar = "Hello, world!"; %>  <!-- %! means a declaration -->
    <%= out.println(HelloVar); %>  <!-- %= outputs the value of an expression -->

    <jsp:scriptlet>  <!-- Alternate format -->
      String HelloVar = "Hello, world!";
      out.println(HelloVar);
    </jsp:scriptlet>
  </body>
</html>
      
Can separate code from HTML markup? No?
Descriptions & tutorials Tutorial: Sun's JavaServer Pages Tutorial

PHP

Summary
  • Uses own language, PHP, with "syntax borrowed from C, Java and Perl"
  • Embeds scripting commands in HTML (but see PHP templates, below)
  • Provides PHP interpreter as Apache module, mod_php
  • Available for nearly every platform
  • Files typically named with ".php" (or similar) extension
Sample code
<html>
  ...
  <body>
    <?php $HelloVar = "Hello, world!"; ?>
    <?php echo $HelloVar; ?>  <!-- Outputs the value of an expression -->
  </body>
</html>
      
Can separate code from HTML markup? Yes, via one of two third-party extensions to PHP which permit the use of "template" files:

FastTemplates
or
PHP Base Library (PHPLIB)

"Template" files are HTML documents containing PHP variables in {curly braces}. Separate, associated PHP files contain programming logic (instantiations of a 'template' class), which generate output to dynamically replace these variables. Here's a sample excerpt from a template file:
<html>
  ...
  <body>
     {HelloVar}
  </body>
</html>
    
Descriptions & tutorials Tutorial: php.net's PHP Tutorial (with links to other, more extensive tutorials)

eXtensible Server Pages (XSP)

Summary
  • Pure XML
  • Uses <xsp: ...> namespace for tags
  • Logic blocks can be intermingled with content or be kept separate
  • Compiled into binary code (Java servlets, Perl classes [object-oriented modules] ...) before returning output
  • XSP processors typically implement an intrinsic caching scheme
There are at least two (language-specific) XSP implementations to date:
  • Apache XML Project's Cocoon (Java-based)
  • Matt Sargeant's AxKit (Perl-based, requires mod_perl)
Sample code
<!-- This example uses Cocoon and Java -->
...
<xsp:page xmlns:xsp="http://www.apache.org/1999/XSP/Core" language="java">

  <xsp:logic>
    String helloVar = "Hello, World!";
  </xsp:logic>

  <page>
    <body>
      <!-- Creates a new element in the XML document named "greeting" -->
      <xsp:element name="greeting">
        <xsp:expr>helloVar</xsp:expr>  <!-- Outputs the value of an expression -->
      </xsp:element>
    </body>
  </page>
</xsp:page>
<!-- This example uses AxKit and Perl -->
...
<xsp:page xmlns:xsp="http://www.apache.org/1999/XSP/Core" language="Perl">

  <xsp:logic>
    $helloVar = "Hello, world!";
  </xsp:logic>

  <page>
    <body>
      <!-- Creates a new element in the XML document named "greeting" -->
      <xsp:element name="greeting">
        <xsp:expr>$helloVar</xsp:expr>  <!-- Outputs the value of an expression -->
      </xsp:element>
    </body>
  </page>
</xsp:page>
Both of these examples generate the following XML document:
<page>
  <body>
    <greeting>Hello, world!</greeting>
  </body>
</page>
      
which, in turn, can be further processed by XSLT stylesheet(s) or otherwise to generate HTML or other output formats.
Can separate code from XML markup? Yes. In the Cocoon environment, see the second and third options listed under "3 types of XSP pages" in David Parry's XSP Tutorial.

We haven't seen any comparable documentation for AxKit, but it does support taglibs, so it may support similar methods of separation.
Descriptions & tutorials (See the Cocoon and AxKit Web sites, above.)

URL:http://seaotter.berkeley.edu/xml/dynpagelangs.html
Last modified on Wednesday, 09-May-2001 15:59:00 PDT