Concepts of Programming Languages

(Sean Pound) #1
document,^21 using the transformations described in the XSLT document. The
XSLT document specifies transformations by defining templates, which are
data patterns that could be found by the XSLT processor in the XML input file.
Associated with each template in the XSLT document are its transformation
instructions, which specify how the matching data is to be transformed before
being put in the output document. So, the templates (and their associated pro-
cessing) act as subprograms, which are “executed” when the XSLT processor
finds a pattern match in the data of the XML document.
XSLT also has programming constructs at a lower level. For example, a
looping construct is included, which allows repeated parts of the XML docu-
ment to be selected. There is also a sort process. These lower-level constructs
are specified with XSLT tags, such as <for-each>.

2.20.2 JSP


The “core” part of the Java Server Pages Standard Tag Library ( JSTL) is
another markup/programming hybrid language, although its form and pur-
pose are different from those of XSLT. Before discussing JSTL, it is necessary
to introduce the ideas of servlets and Java Server Pages ( JSP). A servlet is an
instance of a Java class that resides on and is executed on a Web server system.
The execution of a servlet is requested by a markup document being displayed
by a Web browser. The servlet’s output, which is in the form of an HTML
document, is returned to the requesting browser. A program that runs in the
Web server process, called a servlet container, controls the execution of serv-
lets. Servlets are commonly used for form processing and for database access.
JSP is a collection of technologies designed to support dynamic Web docu-
ments and provide other processing needs of Web documents. When a JSP
document, which is often a mixture of HTML and Java, is requested by a
browser, the JSP processor program, which resides on a Web server system,
converts the document to a servlet. The document’s embedded Java code is
copied to the servlet. The plain HTML is copied into Java print statements
that output it as is. The JSTL markup in the JSP document is processed, as
discussed in the following paragraph. The servlet produced by the JSP proces-
sor is run by the servlet container.
The JSTL defines a collection of XML action elements that control the
processing of the JSP document on the Web server. These elements have the
same form as other elements of HTML and XML. One of the most commonly
used JSTL control action elements is if, which specifies a Boolean expression
as an attribute.^22 The content of the if element (the text between the opening
tag (<if>) and its closing tag (</if>)) is HTML code that will be included
in the output document only if the Boolean expression evaluates to true. The
if element is related to the C/C++ #if preprocessor command. The JSP


  1. The output document of the XSLT processor could also be in HTML or plain text.


2.20 Markup/Programming Hybrid Languages 105


  1. An attribute in HTML, which is embedded in the opening tag of an element, provides further
    information about that element.

Free download pdf