Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Understanding LXP Mark-Up

While LXP performs programmatic tasks, one of the aims of LXP is to achieve these tasks without having to change the general syntax that one uses when putting together HTML (or XHTML) mark-up. On the server, an LXP document appears to be a normal HTML file with some unfamiliar tags.

Here is an introductory example of a simple LXP document:

<lxp>
  <dock type="init">
    <include src="parts/init.lxp" />
  </dock>
  <include src="parts/head.html" />
  
  <h1>Welcome</h1>
  
  <hr width="400">
  
  <if lxp.authenticated='t'>
    Welcome to my webpage, <putcookie name="user" />
  </if>
  <else>
    <strong>Please login.</strong>
    <include src="parts/login.lxp" />
  </else>
  
  <include src="parts/foot.html" />
</lxp>

LXP Tags

A tag (formally called an element) is defined as a structure in a document beginning with a less-than symbol (<) and ending with a greater-than symbol (>). Tags always begin with a name, which defines the nature of the tag, and can optionally have a set of space-delimited attributes. Attributes are always described in the form of a name=value pair, where name is an attribute name unique to that tag, and value is some arbitrary value assigned to that attribute.

All of LXP's tags follow the same general structure of any mark-up language. Tags begin a region (or block) with an opening tag (e.g., <tag>), and close each region with an associated slash-prefixed closing tag (e.g., </tag>.

As with HTML and XML, some tags do not require closing. These are called empty element tags, and do not define a region, but perform a one-time operation. Empty element tags are typically characterized by a trailing forward slash at the end of the tag (e.g., <tag />.

LXP's parser does not syntactically require trailing-slashes in empty element tags, though omitting them can cause unpredictable behavior in some circumstances. For example, nesting the <include> tag can cause some confusion to branching logic if trailing slashes are omitted. This is because the <include> tag may be either an empty-element tag (as in the case of an external document inclusion), or an opening tag requiring a closing tag (as in the case of the direct SQL inclusion).

Note: It is a good idea to be in the habit of using trailing slashes in empty-element tags. In HTML, some tags do not formally require a trailing slash (e.g., <br> versus XHTML's <br />). With the rise of XHTML and XML, however, requirements for mark-up–based documents are becoming more strict.

Both opening and empty-element tags have names, and may also contain some number of attributes. While the name describes the intent of a tag, the attributes typically define the details of the operation to be performed, and vary in their meaning from tag to tag. A closing tag should only have a name, immediately following its initial forward slash (e.g., </tag>).

LXP tag and attribute names are generally case-insensitive, though there are times when an attribute name refers literally to a variable's name (such as in the <if> tag). In these instances, case can matter, depending on the case conventions you use with your variables. The examples in this document prefer lowercase, following the lead of the XHTML standard (which defines element names and attributes as all lowercase).

Example 13-6 shows a simple LXP mark-up region with one opening tag, one closing tag, and two empty-element tags within their defined region.

Example 13-6. A Simple LXP mark-up region

<lxp>
  <setvar example="test" />
  <putvar name="example" />
</lxp>

LXP aims for simplicity and seamlessness in application development, and this basic structural aspect of LXP is an example of this ethic.

LXP Regions

Arguably the most important LXP tag is the <lxp> tag itself, which enables an LXP region. This is similar to a <script> tag, or the PHP short tag, in that it instructs the LXP module to begin looking for LXP content.

Unlike PHP, however, while parsing an LXP region the module will simply ignore any tags that it does not recognize as an LXP tag. The <lxp> tag simply enables the ability to use LXP tags in a given region without impairing your ability to write normal HTML mark-up (though the effect of LXP tags can control which parts of the HTML are displayed).

It should follow from this discussion that </lxp> closes an LXP region and disables the ability to use LXP tags until the next <lxp> tag is opened.

Note: An LXP document does not automatically look for LXP tags. A document will be rendered faster if LXP regions are limited to areas requiring LXP capabilities, as it is more involved to parse an LXP region for dynamic content than it is to process a plain HTML region.


 
 
  Published courtesy of O'Reilly Design by Interspire