Presenting XML

A Framework for XML/XSL Application Development

Daniel Parker

The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Mozilla Public License Version 1.1

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.

The Original Code is Presenting XML.

The Initial Developer of the Original Code is Daniel Parker. Portions created by Daniel Parker are Copyright (C) 2003 Economic Technology, Inc. All Rights Reserved.

Contributor(s): Bob Bartholomay

Alternatively, the contents of this file may be used under the terms of the LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE") license, in which case the provisions of LGPL License are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the LGPL License and not to allow others to use your version of this file under the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the LGPL License. If you do not delete the provisions above, a recipient may use your version of this file under either the MPL or the LGPL License.


Table of Contents

I. Guide
1. Overview
What is Presenting XML?
Model-View-Presenter Architecture
2. Getting Started
Installation
Presenting XML
Java Development Environment
Jakarta Tomcat
WAP browser emulator
Sample Web Application
Building the Sample Web Application
Exploring the Sample Configuration Files
3. Resources Script
Introduction
Basic Concepts
The Books Resources Script
Properties, Named Resources, and Annonymous Resources
Managing the Resources Script
Pipelines
Serializers
Redirection
Device Independence
4. Configuration
Initialization Process
5. Caching
Introduction
Caching System Files
Caching Dynamic XML Content
Cache Management
6. Validation Architecture
Types
Fields
II. Core Reference
7. Properties, Named Resources, and Annonymous Resources
8. Pipeline Body
9. Core Instructions
px:app
Attributes
Content
Description
Examples
px:cachingOptions
Attributes
Content
px:choose
Attributes
Content
See also
px:clientOptions
Attributes
Content
px:clientRedirect
Attributes
Content
Description
See also
px:content
Attributes
Content
Examples
See also
px:customSerializer
Attributes
Content
Examples
See also
px:doFault
Attributes
Content
Examples
px:dynamicContent
Attributes
Content
Examples
See also
px:field
Attributes
Content
Examples
See also
px:fieldAttributeMap
Attributes
Content
See also
px:fieldElementMap
Attributes
Content
See also
px:filter
Attributes
Examples
See also
px:include
Attributes
Content
px:key
Attributes
Content
Examples
px:localRedirect
Attributes
Content
Description
See also
px:mapRequest
Attributes
Content
Description
See also
px:mapRequest
Attributes
Content
Description
Examples
px:matchDevice
Attributes
Content
Description
See also
px:matchRequestURI
Attributes
Content
Description
See also
px:otherwise
Attributes
Content
px:page
Attributes
Content
Examples
See also
px:parameter
Attributes
Content
Description
See also
px:recordSetMapping
Attributes
Content
See also
px:resources
Attributes
Content
px:saxFilter
Attributes
Content
Examples
See also
px:serializer
Attributes
Content
See also
px:serverRedirect
Attributes
Content
Description
See also
px:show
Attributes
Content
Description
px:style
Attributes
Content
Examples
See also
px:systemContent
Attributes
Content
Examples
See also
px:transform
Attributes
Content
Examples
See also
px:validateRequest
Attributes
Content
Description
Examples
px:when
Attributes
Content
III. Optional Module Reference
10. Flat File Module
px:commentSymbol
Attributes
Content
px:field
Attributes
Content
See also
Notes
px:fieldDelimiter
Attributes
Content
Description
Notes
px:fileHeader
Attributes
Content
px:fileLayout
Attributes
Content
Examples
px:flatFileContent
Attributes
Content
Examples
See also
px:flatFileSerializer
Attributes
Content
Examples
See also
px:quoteSymbol
Attributes
Content
Description
px:record
Attributes
Content
See also
px:recordDelimiter
Attributes
Content
Description
px:recordMapping
Attributes
Content
11. SQL Module
px:jdbcConnectionPool
Attributes
Content
px:sqlContent
Attributes
Content
Examples
See also
px:sqlQuery
Attributes
Content
Examples
12. SUN Multi Schema Validator Module
px:msvFilter
Attributes
Examples
13. FOP Module
px:fopSerializer
Attributes
Content
Examples
14. Mail Module
px:attachment
Attributes
Content
Description
px:mailAccount
Attributes
Content
Examples
px:message
Attributes
Content
px:part
Attributes
Content
Description
px:sender
Attributes
Content
px:sendMail
Attributes
Content
Examples
15. Stream Filter Module
px:appendChild
Attributes
Content
Description
See also
px:input
Attributes
Content
See also
px:insertSiblingAfter
Attributes
Content
Description
See also
px:insertSiblingBefore
Attributes
Content
Description
See also
px:output
Attributes
Content
See also
px:remove
Attributes
Content
Description
See also
px:streamFilter
Attributes
Content
Examples
px:update
Attributes
Content
Description
Examples
Examples
See also
px:variable
Attributes
Content
Description
A. Building the Source Distribution
Ant
Building Presenting XML
B. Configuring Tomcat
Configuring Tomcat Version 4.0
Deploying in the development source tree
Deploying a Web Application aRchive (WAR) file.
Configuring Tomcat Versions 3.x
C. Adapters
Transformer Adapters
Changing between Saxon and Xalan
D. System Configuration Reference
px:cacheManager
Attributes
Content
px:config
Attributes
Content
px:device
Attributes
Content
px:deviceMap
Attributes
Content
px:devices
Attributes
Content
px:documentBuilder
Attributes
Content
px:logger
Attributes
Content
px:outputProperties
Attributes
Content
px:patternMatcher
Attributes
Content
px:properties
Attributes
Content
px:property
Attributes
Content
px:saxParser
Attributes
Content
px:systemProperties
Attributes
Content
px:transformer
Attributes
Content
E. Presenting XML Console App
Starting Presenting XML as a standalone console application
Glossary

Guide

Chapter 1. Overview

What is Presenting XML?

Presenting XML is an extendible, component-based framework for XML/XSLT applications that aims at achieving a complete separation of content from presentation. It supports styling XML content with XSLT stylesheets, as well as additional processing to other formats like pdf. It supports targeting different types of devices (e.g. browsers,handhelds) with different flavors of markup (e.g. HTML,WML.)

The promise of an XML/XSLT based approach to achieve separation of content and presentation is compelling. Many companies are moving in this direction, away from approaches like JSPs.

There are a number of frameworks out there that support publishing content styled with XSLT sheets. Apache Coccon is one that is well known in the open source community. Most existing approaches, however, do not allow for much richness in the way that XSLT sheets get selected to style content. Obviously required is the ability to choose stylesheets based on target device, but that is not enough.

Dynamic, interactive sites require a much richer way of selecting styleheets at runtime. The selection of a stylesheet may need to depend on parameters in the http request, and also on tags in the supplied XML content. A request may be for a summary or a detailed view; we may want to style the same content differently depending on the view requested. A request may be for dynamic content to be fed back from some remote resource; that request may fail, and we may end up needing to style error tags with an error sheet.

Presenting XML attempts to recognize the device and determine its supported MIME types, and then sends the request to the most conforming request handler. The request handler authenticates the request, and, if the request passes, assembles a pipeline for servicing the request. Alternate pipelines may be assembled based on tests of XPATH expressions matched on request parameters. Simple examples with XML, XSLT, and java are used to illustrate how this works.

The current version can be configured to work with any fully TrAX conformant XSLT transformer, including Saxon and Apache Xalan. The default configuration is for the Saxon XSLT transformer, the Apache Xerces XML parser, and the Apache fop pdf driver. Future versions will support any conformant XML parser.

Configuration is based on XML files.

Model-View-Presenter Architecture

Presenting XML provides a Model-View-Presenter framework for web applications that supports:

  • Selecting dynamic content, by implementing a SelectHandler Java interface.
  • Presenting a view of the content to a user, by applying an XSLT stylesheet.
  • Changing dynamic content, by implementing an UpdateHandler Java interface.

The nature of the model data itself is largely outside the scope of the Presenting XML pipeline framework; the content management layer merely specifies a way for transferring XML back to the presenter as SAX events. Where that content comes from is no business of the framework; it could come from Entity Java Beans, direct access to the database, or system files - the framework doesn't care.

The distribution provides components that implement adapters for certain kinds of content, including XML files, delimited and fixed length flat files, and SQL databases. It also provides a component that implements a more general adapter for user defined dynamic content.

The presenter gets back a representation of the data as a stream of SAX events. The presenter then needs to do something - perhaps style the XML source with an XSLT sheet and send the result back to a browser, or perhaps redirect the request to another url. These actions are described declaratively in a resources script.

Chapter 2. Getting Started

Installation

Presenting XML

The full Presenting XML distribution may be obtained from https://sourceforge.net/projects/presentingxml/. It includes the source code and build files as well as binary jar files, a sample web application, and run scripts. It includes api documentation and a user guide. It also includes a number of third party jar files.

The directory layout under the top level presentingxml directory is as follows:

  • src/java - Directory containing the java source files for the Presenting XML framework.

  • src/docs - Directory containing the DocBook XML source files for documentation.

  • src/resources - Directory containing the startup.xml file for managing configuration.

  • modules - Directory containing the source code and third party jar files for optional modules.

  • docs - Directory containing javadoc and a user guide.

  • lib/ - Directory containing jar files that will be copied to the web server lib deployment directory.

  • lib/local - Directory containing your own jar files you want to use in a console app or web app.

  • lib/optional - Directory containing jar files copied during the build process from the modules/<module>/lib directories.

  • lib/servletapi - Contains the servlet.jar file used in building the distribution files.

  • tools/junit - Directory containing the junit jar file for the test suite.

  • tools/ant - Directory containing the ant jar files for the builds.

  • webapps/bookstore - Directory containing a sample web application.

  • consoleapps - Directory containing examples of running presentingxml from the command line.

  • tests - Directory containing junit tests.

  • build - Directory containing temporary files during the build process.

The following software components are not included and must be downloaded and installed separately:

  • Java development environment.

  • Servlet 2.2 compliant web server, such as Jakarta Tomcat

  • A WAP browser emulator.

Java Development Environment

Presenting XML requires Java JDK 1.3 or later (it will not work with earlier versions.) It has been tested with Sun's Java JDK 1.3.1, on Windows 2000 and on Linux.

Jakarta Tomcat

You will need to configure your web server to work with Presenting XML. This section describes how to do that for Jakarta Tomcat 4.0.

The distribution files for the Jakarta Tomcat 4.0 web server may be obtained from http://jakarta.apache.org/site/binindex.html.

The steps to configure Jakarta Tomcat to work with Presenting XML are as follows:

  • Edit the server.xml file in the tomcat conf directory. Add the following Context element in the server.xml file (changing docBase as appropriate):

    
      <Context path="/bookstore" 
        docBase="C:/Projects/presentingxml/webapps/bookstore" 
        debug="0" 
        reloadable="true" > 
      </Context>
    
    

  • Set the environmental variable JAVA_HOME to a version of the jdk 1.3 or above, i.e.

    set JAVA_HOME=C:\tools\java\jdk1.3.1
    
    (changing C:\tools as appropriate), or add the above line to the top of the startup.bat file (tomcat.sh for Unix) in the jakarta tomcat bin directory.

WAP browser emulator

Presenting XML requires a WAP browser emulator for viewing the sample WML pages. A free WAP browser emulator may be obtained from OPENWAVE.

Sample Web Application

Before building the sample web application, be sure to build the presentingxml project. From the command prompt in the top level presentingxml directory, enter build.

The webapps/bookstore subdirectory is the "document root" for a sample web application. It is set up to be compatible with the Web Application Architecture (WAR) standard. It has the following components:

  • config - Directory containing the presentingxml.xml configuration file.

  • pages - Directory containing the pages.xml file.

  • documents - Directory containing the document catalog and any system XML files.

  • styles - Directory containing the style catalog and the stylesheets.

  • java - Directory containing the java source files for the sample.

  • build - Directory containing temporary files during the build process.

  • WEB-INF/web.xml - The Web Application Deployment Descriptor for the sample application.

  • WEB-INF/lib - Directory that will contain the deployed jar files.

Building the Sample Web Application

Set the environmental variable JAVA_HOME to a version of the jdk 1.3 or above, i.e.

set JAVA_HOME=C:\tools\java\jdk1.3.1
(changing C:\tools as appropriate), or add the above line to the top of the build.cmd file (build.sh for Unix) in the webapps/bookstore directory.

Build the sample web application by entering build at the command prompt in the webapps/bookstore directory.

If everything has gone correctly you should now be able to run the sample web application.

  • Start the tomcat server by entering startup at the command prompt in the jakarta tomcat bin directory.

  • Open the following URL in a browser: http://localhost:8080/bookstore/pages/books

  • Now click on one of the categories in the left panel.

  • For a pdf example, under the Featured Books section in the left panel, click on "Pulp"

  • Finally, try opening the books URL http://localhost:8080/bookstore/pages/books in a WAP browser emulator.

  • Shutdown the tomcat server by entering shutdown at the command prompt in the jakarta tomcat bin directory.

Exploring the Sample Configuration Files

Basic Configuration

The config subdirectory contains the configuration file presentingxml.xml.

Pages

The pages subdirectory contains the pages.xml file. The purpose of the pages.xml file is to define the pages that a client may request of the web server. Each request for a page has a specified source of XML content and the rules for styling that XML content. The source of XML content is represented by a document name. The rules for styling that XML content are specified by transform and serialize actions. A style attribute specifies which stylesheet to use.

Documents

The documents sub-directory contains the configuration file documents.xml. The purpose of the documents.xml file is to define sources of XML content and to give them names. A source of XML content need not exist as a document per se. It may exist as a java object which is capable of feeding start/end elements into a SAX 2 ContentHandler.

The documents.xml defines a source of XML content with a url (if it is really an XML file) or a request handler (if the data will be coming from a SAX source.)

There are two types of request handlers.

  • SelectHandler - Defines an interface for getting dynamic XML content (e.g. a document, results from a database query.) This content may be cached depending on the caching options in effect. An example is BookCatalog under the java/samples/books subdirectory.

  • UpdateHandler - Defines an interface for posting data values (e.g. updating values in a database.) A UpdateHandler may also return dynamic XML content. If it does, that content is never cached.

Styles

The styles subdirectory contains the configuration file styles.xml and the XSLT stylesheets.

web.xml

The WEB-INF/web.xml file is the Web Application Deployment Descriptor for the sample application.


<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
    <servlet>
        <servlet-name>presenter</servlet-name>
        <servlet-class>com.presentingxml.presenter.http.PresenterServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <init-param>
            <param-name>appName</param-name>
            <param-value>myapp</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>presenter</servlet-name>
        <url-pattern>/pages/*</url-pattern>
    </servlet-mapping>
</web-app>
Note the init-param element, which defines the name of the web app as "myapp."

Chapter 3. Resources Script

Introduction

Basic Concepts

The purpose of a resources script is to provide a catalog of named pages that encapsulate a service of some kind. A page is associated with actions - transforming XML to HTML through the application of a stylesheet, serializing XML to PDF, transforming a flat file to XML, updating records in a database, and so forth.

The Books Resources Script

A simple example is shown below.

Example 3.1. The Books Resources Script


<px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
              xmlns:myapp="http://www.presentingxml.com/myapp"
              ns="http://www.presentingxml.com/myapp">
              
  <px:app>
    <px:mapRequest>
      <px:matchRequestURI match="/bookstore/pages/(.+)">$1</px:matchRequestURI>
    </px:mapRequest>
  </px:app>
              
  <px:page name="books">
    <px:parameter ns="" name="category"/>
    <px:show>
      <px:transform>
        <px:content ref="myapp:books"/>
        <px:style ref="myapp:books"/>
      </px:transform>
    </px:show>
  </px:page>
  
  <px:dynamicContent name="books" className="samples.books.BookCatalog">        
    <px:key>
      <px:field name="category"/>
    </px:key>
  </px:dynamicContent>

  <px:style name="books" href="html/books/books.xsl"/>

</px:resources>              

The books resources script consists of a px:resources element and some subelements, including the px:app, px:mapRequest, px:page, px:show, px:transform, px:content, px:dynamicContent and px:style subelements.

Each element in the resources script has a prefix px:. The resources element associates the px: prefix with the Presenting XML namespace in the declaration xmlns:px="http://www.presentingxml.com/PresentingXML". In this way, the page, content and style elements are identified as belonging to Presenting XML, not to the author of the books content and stylesheet.

Note the px:app element at the head of the books resources script. The app element optionally contains a px:mapRequest element that defines the mapping of request URIs into page names. If no request mapper element is specified, the default is to look for a page with whatever namespace happens to be in scope and a local name the same as the request URI. In the example, we see a single px:matchRequestURI element that maps a request URI like /bookstore/pages/welcome into a page with namespace "http://www.presentingxml.com/myapp" and local name "welcome".

The books resources script defines a number of resources: a page, a document, and a style. These names belong to the author of the books resources. Each resource is given a name. A name has two parts, a local name and a namespace URI. The local name is specified by a name attribute. The namespace URI is specified by a ns attribute. If the element defining the resource does not specify a ns attribute, the namespace URI defaults to that of the nearest ancestor element that does have a ns attribute, or the empty string if there is none. In the books example, therefore, the page takes a local name "books" and the namespace URI "http://www.presentingxml.com/myapp". The prefix myapp: is associated with that namespace.

Pages are defined with the page element. In the books page element above, we see a page element that defines a response, which consists of a transform instruction applied to a document and a stylesheet. The consequence of this definition is that if a browser sends a request to the web server for the page named books, the document named "books" will be styled with the stylesheet named "books", resulting in an HTML page being returned to the browser.

Documents are defined with a content element. In the books example above, we see a px:dynamicContent element with a className attribute, associating the document "books" with the Java class sample.books.BookCatalog.

public class BookCatalog implements SelectHandler {
  public void doRequest(PageContext context, Book parameters, 
  ContentWriter contentWriter) throws PresentingXMLException {
    // Implementation
  }

  public long getLastModified(RuntimeContext context, Book key, 
  long timestamp, long elapsed)  {
    // Indicate changed if older than 10 seconds
    return elapsed > 10000 ? timestamp : timestamp + elapsed;  
  }
}
The consequence of this definition is that when the document named "books" is accessed, the doRequest method of the BookCatalog object is called. The Presenting XML framework is responsible for mapping request parameters to properties declared in the Book interface; the BookCatalog object is responsible for feeding start/end elements to the SAX 2 ContentHandler.

Note that the doRequest method defined above takes a user defined interface Book as its second argument,

public interface Book {
  public String getCategory();
}
The Presenting XML framework creates a proxy class that implements this interface at runtime. If the HTTP request has the parameter category, the value of that parameter may be obtained with the getCategory() method. The method signatures on the user defined parameters interface need to follow the standard naming conventions for beans.

Stylesheets are defined with the style element. In the books example above, we see a px:style element with an href attribute, associating it with the relative url "html/books/books.xsl". By default this relative url is resolved relative to the location of the resources script. The base may be overriden with an xml:base attribute.

Properties, Named Resources, and Annonymous Resources

There are three kinds of elements that may appear in a resources script:

  • properties - elements that affect the execution of instructions within a scope,
  • named resources - resources that can be referenced by name elsewhere in the script, and
  • annonymous resources - elements that appear in place inside other elements.

Managing the Resources Script

As the resources script becomes larger, it becomes desirable to reorganize it, splitting off document and style elements into separate files, in separate directories. For example, we may wish to have the directory tree:

  • pages - Directory containing the books pages.xml file.

  • documents - Directory containing the documents.xml file.

  • styles - Directory containing the styles.xml file, with subdirectories containing the actual stylesheets.

The document and style definitions are now contained in two separate files, documents.xml and styles.xml. We need to import these definitions in the pages.xml file, and we do that using the include instruction.

Example 3.2. The Reorganized Books Resources Script


<px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
              xmlns:myapp="http://www.presentingxml.com/myapp"
              ns="http://www.presentingxml.com/myapp">
  
  <px:include href="../documents/documents.xml"/>
  <px:include href="../styles/styles.xml"/>
              
  <px:app>
    <px:mapRequest>
      <px:matchRequestURI match="/bookstore/pages/(.+)">$1</px:matchRequestURI>
    </px:mapRequest>
  </px:app>
  
  <px:page name="books">
    <px:parameter ns="" name="category"/>
    <px:show>
      <px:transform>
        <px:content ref="myapp:books"/>
        <px:style ref="myapp:books"/>
      </px:transform>
    </px:show>
  </px:page>

</px:resources>              

Pipelines

A pipeline body defines the sequence of steps applied to content to transform it into an XML stream for the serializer. A pipeline starts with content, passes it through a number of stages where it gets filtered and transformed, and finally hands it off to a serializer.

The simplest possible pipeline is a single px:content instruction. Such a pipeline simply passes the content "as is" to the serializer.

Consider the following pipeline body.


    <px:transform>
      <px:transform>
        <px:systemContent href="documents/mixed-up.xml"/>
        <px:saxFilter className="PreFilter"/>
      </px:transform>  
      <px:style href="styles/filter.xsl"/>     
      <px:saxFilter className="PostFilter"/>     
    </px:transform>

This pipeline body may be thought of as a sequential process that executes from right to left. The inner transform is executed first. Here, the content mixed-up.xml is passed through the SAX filter PreFilter, and then streamed to the outer transform. In the outer transform, the result tree is first transformed with the XSLT stylesheet filter.xsl, and then passed through the SAX filter PostFilter, finally making its way to the serializer.

A pipeline body may have any number of nested transform stages. The innermost transform stage must contain a content instruction. Within a transform stage, there may be any number of filters and XSLT transformations that are executed in document order.

Filters

A filter performs processing on the XML tags at a lower stage before passing them on to a higher stage.

Choices

Presenting XML supports a rich variety of ways for selecting a pipeline body at runtime. Test expressions may be used to pick one of a number of candidate pipeline bodies based on the request parameters. The example below shows a page that is styled differently depending on whether the HTTP request has a parameter named "category."

Example 3.3. The Books Resources Script with Choices


<px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
              xmlns:myapp="http://www.presentingxml.com/myapp"
              ns="http://www.presentingxml.com/myapp">
  
  <px:include href="../documents/documents.xml"/>
  <px:include href="../styles/styles.xml"/>
                
  <px:app>
    <px:mapRequest>
      <px:matchRequestURI match="/bookstore/pages/(.+)">$1</px:matchRequestURI>
    </px:mapRequest>
  </px:app>
  
  <px:page name="books">
    <px:parameter ns="" name="category"/>
  
    <px:show>
      <px:choose>
        <px:when test="$category">
          <!--  request has parameter category -->
          <px:transform>
            <px:style ref="myapp:books"/>
            <px:content ref="myapp:books"/>
          </px:transform>
        </px:when>
        <px:otherwise>
          <!--  request does not have parameter category -->
          <px:transform>
            <px:style ref="myapp:welcome"/>
            <px:content ref="myapp:request"/>
          </px:transform>
        </px:otherwise>
      </px:choose>
    </px:show>
  </px:page>
  
</px:resources>              

The syntax for a test expression is a small subset of the syntax for an XPath expression, including the parts that make sense for testing parameter values.

Examples of test expressions are shown below.

  • "$title or $author"
  • "$category='X' or $category='F'"
  • "$category='X' and $tax = 0.15"
  • "$category='X' and $price &gt; 5.0"

Serializers

A serializer takes the output of a transformer - an XML or HTML tree - and serializes it to a byte stream before sending it back to the client device. The default serializer simply transforms the tree to text and sends that back as a byte stream.

The example below illustrates the use of a serializer to produce a pdf document:

Example 3.4. A Serializer to Produce PDF


<px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
          xmlns:myapp="http://www.presentingxml.com/myapp"
          ns="http://www.presentingxml.com/myapp">
                
  <px:app>
    <px:mapRequest>
      <px:matchRequestURI match="/bookstore/pages/(.+)">$1</px:matchRequestURI>
    </px:mapRequest>
  </px:app>

  <px:page name="pulp">
    <px:clientOptions caching="yes"/>      
    <px:cachingOptions caching="yes" revalidate="synch"/>      
    <px:show>
      <px:fopSerializer/>
      <px:transform>
        <px:style ref="myapp:novel-fo"/>
        <px:content ref="myapp:pulp"/>
      </px:transform>
    </px:show>
  </px:page>
  
  <px:systemContent name="pulp" href="books/pulp.xml"/>        
  
  <px:style name="novel-fo" href="fo/books/novel.xsl"/>
</px:resources>

A serializer is defined with the serializer element. The example above uses the apache fop serializer.

Redirection

The example below shows the "update-cart" page which updates a shopping cart in a Java UpdateCart object, adding a new book title, and then performs a client-side redirect to the "books" page. The URI of the "books" page is evaluated as an XPATH expression that can refer to any XML content generated in the pipeline that appears in its content, or to any parameters passed to the page.


  <px:page name="update-cart">   
    <px:parameter ns="" name="category"/>
    <px:parameter ns="" name="bookId"/>
    <px:parameter ns="" name="title"/>
    
    <px:show>
      <px:clientRedirect select="concat('/bookstore/pages/books?category=',$category)">
        <px:dynamicContent className="samples.books.UpdateCart"/>        
      </px:clientRedirect> 
    </px:show>
  </px:page>

Device Independence

Presenting XML uses the <xsl:output> element in the XSLT stylesheet to obtain information about the MIME type that the stylesheet produces. It is therefore important that the media-type attribute of the <xsl:output> element is assigned a value, for example "text/html" for HTML stylesheets and "text/vnd.wap.wml" for WML stylesheets.

The figure below shows the px:devices section in the system configuration file. It defines a number of known devices and the MIME-types they accept. It also defines maps from the HTTP User-Agent to the device. If the device can be identified, Presenting XML will use that information first. If the device cannot be identified, Presenting XML will use the HTTP accept header.

Figure 3.1. Device Configuration


  <px:devices>
    <!-- Define devices and accepted MIME types -->
    <px:device name="explorer" 
               accept="text/html,application/pdf"/> 
    <px:device name="pocketexplorer"/>
    <px:device name="handweb"/>
    <px:device name="avantgo"/>
    <px:device name="imode"/>
    <px:device name="opera"/>
    <px:device name="lynx"/>
    <px:device name="java"/>
    <px:device name="wap" 
               accept="text/vnd.wap.wml"/>
    <px:device name="mozilla5" 
               accept="text/html"/>
    <px:device name="netscape" 
               accept="text/html,application/pdf"/>
    
    <!--
    Map a pattern in the User-Agent to a device name.
    A pattern may contain unix wildcards.
    -->
    <px:deviceMap search="MSIE" device="explorer"/> 
    <px:deviceMap search="MSPIE" device="pocketexplorer"/>
    <px:deviceMap search="HandHTTP" device="handweb"/>
    <px:deviceMap search="AvantGo" device="avantgo"/>
    <px:deviceMap search="DoCoMo" device="imode"/>
    <px:deviceMap search="Opera" device="opera"/>
    <px:deviceMap search="Lynx" device="lynx"/>
    <px:deviceMap search="Java" device="java"/>
    <px:deviceMap search="(Nokia)|(UP)|(Wapalizer)" device="wap"/>
    <px:deviceMap search="(Mozilla/5)|(Netscape6/)" device="mozilla5"/>
    <px:deviceMap search="Mozilla" device="netscape"/>
  </px:devices>

Note that the search attribute appearing in the px:deviceMap element can take regular expressions.

The following example shows how the same request URI may be mapped into different pages depending on the device and on the mime types that the device accepts.

Example 3.5. Device Configuration



<px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
              xmlns:myapp="http://www.presentingxml.com/myapp"
              ns="http://www.presentingxml.com/myapp">
  
  <px:include href="../styles/styles.xml"/>
  <px:include href="../documents/documents.xml"/>
  
  <px:app>
    <px:mapRequest>
      <px:matchDevice device="explorer">
        <px:matchRequestURI match="/bookstore/pages/(.+)">$1/explorer</px:matchRequestURI>
      </px:matchDevice>
      <px:matchDevice accept="text/html">
        <px:matchRequestURI match="/bookstore/pages/(.+)">$1/html</px:matchRequestURI>
      </px:matchDevice>
      <px:matchDevice accept="text/vnd.wap.wml">
        <px:matchRequestURI match="/bookstore/pages/(.+)">$1/wml</px:matchRequestURI>
      </px:matchDevice>
    </px:mapRequest>  
  </px:app>
  
  <px:page name ="books/wml">
    <px:parameter ns="" name="category"/>
    <px:show>
      <px:transform>
        <px:style ref="myapp:books/wml"/>
        <px:content ref="myapp:books"/>
      </px:transform>
    </px:show>
  </px:page>
  
  <px:page name ="books/html">
    <px:parameter ns="" name="category"/>
    <px:show>
      <px:transform>
        <px:style ref="myapp:books/html"/>
        <px:content ref="myapp:books"/>
      </px:transform>
    </px:show>
  </px:page>
  
</px:resources>


Suppose in this example we receive the request URI "/bookstore/pages/books".

If the sending device is recognized to be "explorer" according to the rules defined in the presentingxml.xml configuration file, the first request matcher attempts to resolve the request to a page with namespace "http://www.presentingxml.com/myapp" and local name "books/explorer". This fails, since there is no such page, The second request matcher then checks that the device accepts the mine type "text/html" (which it does) and also that there is a page having namespace "http://www.presentingxml.com/myapp" and local name "books/html", which there is.

If the sending device is unrecognized, and the HTTP accept header indicates that the device does not accept mime type "text/html", but does accept mime type "text/vnd.wap.wml", then the third request matcher will attempt to find a page having namespace "http://www.presentingxml.com/myapp" and local name "books/wml".

Chapter 4. Configuration

Table of Contents

Initialization Process

Initialization Process

The config subdirectory is found immediately beneath the document root. The configuration file presentingxml.xml is in the config folder. It contains a number of sections:

  • The transformer section species the jaxp transformer factory that is used. A jaxp transformer factory is any java class that implements the javax.xml.transform.TransformerFactory interface.

  • The device-map section defines a mapping of device descriptions (e.g. "MSIE") to device names (e.g. "explorer"). This roughly follows Cocoon's approach. Regular expressions are allowed for device descriptions.

Chapter 5. Caching

Introduction

The Presenting XML framework supports caching document, stylesheet and page resources. Whether or not a resource can be cached is configurable, and the way in which a resource becomes invalidated - asynchronously or synchronously - is also configurable.

For documents, the framework supports caching both

  • XML content read from system files, and

  • XML content generated dynamically through a SAX 2 ContentHandler.

Documents are optionally cached, depending on the settings in the px:cachingOptions element in scope when the documents are defined. Cached representations are built from the stream of SAX events when the document is initially loaded.

Stylesheets are cached as compiled Templates objects.

Pages are cached as text markup.

Two major issues in caching are object identity and cache entry invalidation:

  • How do we know that two requests are for the same cached node, particularly when the node has been generated dynamically?

  • How can we tell when an entry in the cache needs to be reloaded?

The next sections describe how these two issues are addressed for system files, dynamic content, stylesheets, and pages.

Caching has the result of improving performance but using up valuable memory. The final section describes the role of the cache manager in managing the memory resource, in ensuring that the cached nodes will not grow to the point of overwhelming the available memory.

Caching System Files

The url uniquely identifies a system file.

Caching Dynamic XML Content

A request for dynamic XML content comes with a document name and some parameters. The document name determines the RequestHandler used to handle the request. Different requests, of course, could come with different parameter values and so result in different nodes.

The notion of keys is used to assign an identity to what a RequestHandler writes into a ContentHandler. Keys are set up for dynamic content in the documents.xml file. A key consists of the document name and an ordered sequence of attributes that taken together assigns an identity to the XML content.

When a request for dynamic XML content comes in, the parameters are matched up by name with the attributes that make up the key. The matched parameter values are saved in the key object. These key objects are used to identify the dynamic resource.

If a request for dynamic content originates through a call to the document function in an XSLT stylesheet, an additional parameter may be added to the current parameter set by appending a ? to the document URL followed by a name/value pair.

Suppose, for example, that the key for some dynamic content is defined by the following entry in the documents.xml file:


  <px:systemContent name="categories" className="books.CategoryHandler">        
    <px:key>
      <px:field name="category"/>
    </px:key>
  </px:systemContent>

Now, suppose that the following document function call occurs in an XSLT stylesheet:

<xsl:value-of select="document('categories?category=S',/)//category/@desc" />

Then, the URI resolver that resolves the request for the url categories?category=S will add a parameter named category to the current parameter set that has the value "S".

Cache Management

Chapter 6. Validation Architecture

Table of Contents

Types
Fields

Types

Fields

Core Reference

Table of Contents

7. Properties, Named Resources, and Annonymous Resources
8. Pipeline Body
9. Core Instructions
px:app
Attributes
Content
Description
Examples
px:cachingOptions
Attributes
Content
px:choose
Attributes
Content
See also
px:clientOptions
Attributes
Content
px:clientRedirect
Attributes
Content
Description
See also
px:content
Attributes
Content
Examples
See also
px:customSerializer
Attributes
Content
Examples
See also
px:doFault
Attributes
Content
Examples
px:dynamicContent
Attributes
Content
Examples
See also
px:field
Attributes
Content
Examples
See also
px:fieldAttributeMap
Attributes
Content
See also
px:fieldElementMap
Attributes
Content
See also
px:filter
Attributes
Examples
See also
px:include
Attributes
Content
px:key
Attributes
Content
Examples
px:localRedirect
Attributes
Content
Description
See also
px:mapRequest
Attributes
Content
Description
See also
px:mapRequest
Attributes
Content
Description
Examples
px:matchDevice
Attributes
Content
Description
See also
px:matchRequestURI
Attributes
Content
Description
See also
px:otherwise
Attributes
Content
px:page
Attributes
Content
Examples
See also
px:parameter
Attributes
Content
Description
See also
px:recordSetMapping
Attributes
Content
See also
px:resources
Attributes
Content
px:saxFilter
Attributes
Content
Examples
See also
px:serializer
Attributes
Content
See also
px:serverRedirect
Attributes
Content
Description
See also
px:show
Attributes
Content
Description
px:style
Attributes
Content
Examples
See also
px:systemContent
Attributes
Content
Examples
See also
px:transform
Attributes
Content
Examples
See also
px:validateRequest
Attributes
Content
Description
Examples
px:when
Attributes
Content

Chapter 7. Properties, Named Resources, and Annonymous Resources

Table of Contents

There are three kinds of elements that may appear in a resources script:

  • properties - elements that affect the execution of instructions within a scope,
  • named resources - resources that can be referenced by name elsewhere in the script, and
  • annonymous resources - elements that appear in place inside of other elements.

A property element may appear anywhere in a resources script. The following elements fall into this category.

The example below shows two named resources (the px:content elements), and two properties (the px:cachingOptions elements.)


<px:resources xmlns:px="http://www.presentingxml.com/PresentingXML">

  <px:cachingOptions caching="no"/>

  <px:systemContent name="books" href="documents/books.xml"/>

  <px:systemContent name="authors" href="documents/books.xml">
    <px:cachingOptions caching="yes"/>
  </px:systemContent>

</px:resources>

In this example, the default rule is set so that there is no caching of content. In particular, the books document is not cached. The authors document, on the other hand, is cached.

Any element, in addition to the attributes listed in the reference entries, may have the following attributes.

NameMand.ValueDescription
nsnoURIThe namespace of the resource. Defaults to the namespace in scope.

Chapter 8. Pipeline Body

Table of Contents

Many of the elements listed below permit a pipeline body in their content. A pipeline body defines the sequence of steps applied to content to transform it into an XML stream for the serializer.

A pipeline body may contain one of the following elements:

Chapter 9. Core Instructions

This reference provides an alphabetical list of the core elements that may appear in a resources script.

Below is a list of the core elements in alphabetical order.

px:app

Attributes

NameMand.ValueDescription

Content

Description

Examples

Example 9.1. Example of px:app element.



  <px:app name="bookstore">
    <px:validateRequest><px:page ref="myapp:gatekeeper"/></px:validateRequest>

    <px:mapRequest>
      <px:matchDevice accept="text/html">
        <px:matchRequestURI match="/bookstore/pages/(.+)">$1/html</px:matchRequestURI>
      </px:matchDevice>
      <px:matchDevice accept="application/vnd.wap.wmlc">
        <px:matchRequestURI match="/bookstore/pages/(.+)">$1/wml</px:matchRequestURI>
      </px:matchDevice>
      <px:matchRequestURI match="/bookstore/pages/(.+).pdf">$1/pdf</px:matchRequestURI>
    </px:mapRequest>

  </px:app>

  <px:page name="gatekeeper">
    <px:show>
      <px:localRedirect select="$px:requestURI">
        <px:dynamicContent className="samples.common.BookstoreGatekeeper"/>
      </px:localRedirect>
    </px:show>
  </px:page>

px:cachingOptions

Attributes

NameMand.ValueDescription
cachingyes"yes" or "no"Indicates whether server side caching is in effect for the pages, documents and styles in the current scope.
revalidatenostring A list of revalidation codes with possible values "synch" or "asynch" (or both), or "full" or "none".

Content

None.

px:choose

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the choose instruction.
refnoQNameA reference to a defined top-level px:choose instruction.

Content

See also

px:clientOptions

Attributes

NameMand.ValueDescription
cachingyes"yes" or "no"Indicates client side caching is in effect for the pages in the current scope.

Content

None.

px:clientRedirect

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the redirect instruction.
refnoQNameA reference to a defined top-level px:clientRedirect action.
selectyesExpressionAn XPATH expression which evaluates to a URI.

Content

Optionally, a pipeline body.

Description

Performs a client-side redirect to the URI that results from evaluating the xpath expression in the select attribute.

A client-side redirect sends a URI back to the client, in the expectation that the client will resubmit the request with the new URI. If you want to have state sent with the new URI, you have two options:

  • Add the state in the parameter list of the URI, which you can do in the select attribute of the px:clientRedirect element.
  • Add the state in the HTTP Session object, which you can do in a dynamic content handler appearing in the content of the px:clientRedirect element.

Example 9.2. Example of a client-side redirect.

This example shows the "update-cart" page which updates a shopping cart in a Java UpdateCart object, adding a new book title, and then performs a client-side redirect to the "books" page. The URI of the "books" page is evaluated as an XPATH expression that can refer to any XML content generated in the pipeline that appears in its content, or to any parameters passed to the page.


  <px:page name="update-cart">
    <px:parameter ns="" name="category"/>
    <px:parameter ns="" name="bookId"/>
    <px:parameter ns="" name="title"/>

    <px:show>
      <px:clientRedirect select="concat('/bookstore/pages/books?category=',$category)">
        <px:dynamicContent className="samples.books.UpdateCart"/>
      </px:clientRedirect>
    </px:show>
  </px:page>

px:content

Attributes

NameMand.ValueDescription
refnoQNameA reference to a defined top-level px:content resource.

Content

None.

Examples

Example 9.3. Using a px:content instruction to refer to dynamic content.


<px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
              ns="http://www.presentingxml.com/myapp">

  <px:page name="books">
    <px:parameter ns="" name="category"/>
    <px:show>
      <px:transform>
        <px:style ref="myapp:books"/>
        <px:content ref="myapp:books"/>
      </px:transform>
    </px:show>
  </px:page>

  <px:dynamicContent name="books" className="samples.books.BookCatalog">
    <px:key>
      <px:field name="category"/>
    </px:key>
  </px:dynamicContent>

</px:resources>

px:customSerializer

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the serializer.
classNameyesJava ClassThe name of a java class that implements com.presentingxml.components.serializer.Serializer.

Content

None.

Examples

Example 9.4. Defining an Apache fop serializer.


  <px:serializer name="fop-serializer"
                 className="com.presentingxml.components.serializer.fop.FOPSerializer">
  </px:serializer>

Example 9.5. Serializing an xsl-fo XML tree with an Apache fop serializer to produce pdf.


  <px:page name="pulp">
    <px:show>
      <px:serializer ref="myapp:fop-serializer"/>
      <px:transform>
        <px:style ref="myapp:novel-fo"/>
        <px:content ref="myapp:pulp"/>
      </px:transform>
    </px:show>
  </px:page>

See also

px:doFault

Attributes

None.

Content

One or more action elements from the following list.

Examples

Example 9.6. Apply a stylesheet to a SOAP fault raised in the book-order document handler.


  <px:page name="post-book-order">
    <px:parameter ns="" name="name"/>
    <px:parameter ns="" name="addressLine1"/>
    <px:parameter ns="" name="addressLine2"/>
    <px:parameter ns="" name="city"/>
    <px:parameter ns="" name="state"/>
    <px:parameter ns="" name="zip"/>
    <px:parameter ns="" name="country"/>
    <px:parameter ns="" name="phoneNumber"/>

    <px:show>
      <px:transform>
         <px:style ref="myapp:confirm-order"/>
         <px:content ref="myapp:book-order"/>
      </px:transform>
      <px:doFault>
        <px:transform>
          <px:style ref="myapp:book-order"/>
        </px:transform>
      </px:doFault>
    </px:show>
  </px:page>

px:dynamicContent

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the content resource.
classNamenoJava ClassThe name of a java class that implements com.presentingxml.components.content.dynamic.SelectHandler or com.presentingxml.components.content.dynamic.UpdateHandler.

Content

  • Optionally, a px:key element.

Examples

Example 9.7. Defining a document with reference to a java class that simulates a SAX parser.


<px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
              ns="http://www.presentingxml.com/myapp">

  <px:dynamicContent name="books" className="samples.books.BookCatalog">
    <px:key>
      <px:field name="category"/>
    </px:key>
  </px:dynamicContent>

</px:resources>

px:field

Attributes

NameMand.ValueDescription
namenoNameReference to the name of a parameter. On a request, the field value will be set to that parameter value.

Content

None.

Examples

See px:dynamicContent.

px:fieldAttributeMap

Attributes

NameMand.ValueDescription
nameyesNCNameThe name of the field.
attributeyesQName Identifies an attribute to receive this field's value. The attribute name may contain a field name within curly braces, which will evaluate to the value of the named field.

Content

None.

px:fieldElementMap

Attributes

NameMand.ValueDescription
nameyesNCNameThe name of the field.
elementyesQName Identifies an element to receive this field's value. The element name may contain a field name within curly braces, which will evaluate to the value of the named field.

Content

Optionally, a px:fieldAttributeMap element.

px:filter

Attributes

refnoQNameA reference to a defined top-level filter.

Examples

px:include

Attributes

NameMand.ValueDescription
hrefyesURIA URI identifying a resources script.

Content

None.

px:key

Attributes

Content

Examples

See px:dynamicContent.

px:localRedirect

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the px:localRedirect instruction.
refnoQNameA reference to a defined top-level forward instruction.
selectyesExpressionAn XPATH expression which evaluates to a URI.

Content

Optionally, a pipeline body.

Description

Allows a resources script to pass control locally to another page.

A local redirect computes a new request URI in its select attribute, transfers the request back to the app, skips the validation steps defined in the px:validateRequest element (since its already inside the gate), and attempts to match the new request URI with a page using the rules defined in the px:mapRequest element.

Example 9.8. Example of a local redirect to the original request URI.


  <px:page name="bookstore-gatekeeper">
    <px:show>
      <px:localRedirect select="$px:requestURI">
        <px:dynamicContent className="samples.common.BookstoreGatekeeper"/>
      </px:localRedirect>
    </px:show>
  </px:page>

Note that the variable px:requestURI appearing in the select attribute of the local redirect is a built-in variable that holds the original request URI. This local redirect transfers the request back to the app, skips the validation steps defined in the px:validateRequest element (since its already inside the gate), and attempts to match the request URI with a page using the rules defined in the px:mapRequest element.

px:mapRequest

Attributes

NameMand.ValueDescription
refnoQNameA reference to a defined top-level request matcher.

Content

None

Description

Matches a request to a page.

px:mapRequest

Attributes

NameMand.ValueDescription

Content

One or more elements derived from px:mapRequest, including px:matchDevice and px:matchRequestURI elements.

Description

The mapRequest element supports matching a request URI to a page.

Examples

Example 9.9. Example of px:mapRequest element.


  <px:app name="bookstore">
    <px:mapRequest>
      <px:matchDevice accept="text/html">
        <px:matchRequestURI match="/bookstore/pages/(.+)">$1/html</px:matchRequestURI>
      </px:matchDevice>
      <px:matchDevice accept="application/vnd.wap.wmlc">
        <px:matchRequestURI match="/bookstore/pages/(.+)">$1/wml</px:matchRequestURI>
      </px:matchDevice>
      <px:matchRequestURI match="/bookstore/pages/(.+).pdf">$1/pdf</px:matchRequestURI>
    </px:mapRequest>
  </px:app>

px:matchDevice

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the px:matchRequestURI instruction.
devicenoStringA comma separated list of device names.
acceptnoStringA comma separated list of mime types.

Content

Text.

Optionally, one or more px:mapRequest type elements, including px:matchDevice and px:matchRequestURI elements.

Description

Matches a device to a page.

Example 9.10. Example of matching on a device and request URI.


    <px:matchDevice accept="text/vnd.wap.wml">
      <px:matchRequestURI match="/bookstore/pages/(.+)">$1/wml</px:matchRequestURI>
    </px:matchDevice>

px:matchRequestURI

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the px:matchRequestURI instruction.
matchyesRegexA perl regular expression that matches on the rquest URI.

Content

Text that may include regular expression wildcard characters.

Optionally, one or more px:mapRequest type elements, including px:matchDevice and px:matchRequestURI elements.

Description

Matches a request URI to a page.

Example 9.11. Example of matching on a request URI.


  <px:matchRequestURI match="/bookstore/pages/(.+)">html/$1</px:matchRequestURI>

px:otherwise

Attributes

None.

Content

A pipeline body.

px:page

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the page.
refnoQNameA reference to a defined top-level page.

Content

Optionally, one or more px:parameter elements.

One or more action elements from the following list.

Examples

Example 9.12. Books page.


  <px:page name="books">
    <px:parameter ns="" name="category"/>
    <px:show>
      <px:transform>
        <px:style ref="myapp:books"/>
        <px:content ref="myapp:books"/>
      </px:transform>
    </px:show>
  </px:page>

px:parameter

Attributes

NameMand.ValueDescription
nameyesQNameThe name of the parameter.
selectnoQNameThe name of a parameter in the request. The default is the parameter name.

Content

Optionally, text. If the content contains text, it is evaluated as the value of the parameter.

Description

Used to define the parameters of a px:page element.

See also

px:recordSetMapping

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the page.
refnoQNameA reference to a defined top-level px:recordSetMapping resource.

Content

A document root element, which in turn may contain other elements and a px:recordMapping element.

px:resources

Attributes

NameMand.ValueDescription
nsnoURIThe default namespace for the pages, documents, styles and serializers defined in this resources script.

Content

The list of elements that may be defined with a qualified name at the top level of the resources script includes all the elements that are defined in the px:instructions section of the presentingxml.xml configuration file. These include

px:saxFilter

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the filter.
classNameyesJava ClassThe name of a java class that implements org.xml.sax.XMLFilter.

Content

None.

Examples

Example 9.13. Constructing a SAX pipeline.

The example below shows a resources script that implements a SAX pipeline. PreFilter and PostFilter are the names of Java classes that implement the org.xml.sax.XMLFilter interface.


<px:resources xmlns:px="http://www.presentingxml.com/PresentingXML">

  <px:page name="pipeline">
    <px:show>
      <px:transform>
        <px:systemContent href="documents/mixed-up.xml"/>
        <px:saxFilter className="PreFilter"/>
        <px:style href="styles/filter.xsl"/>
        <px:saxFilter className="PostFilter"/>
      </px:transform>
    </px:show>
  </px:page>

</px:resources>

px:serializer

Attributes

NameMand.ValueDescription
refnoQNameA reference to a defined top-level serializer.

Content

None.

px:serverRedirect

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the px:serverRedirect instruction.
refnoQNameA reference to a defined top-level forward instruction.
selectyesExpressionAn XPATH expression which evaluates to a URI.

Content

Optionally, a pipeline body.

Description

Performs a server-side redirect to the URI that results from evaluating the xpath expression in the select attribute.

A server-side redirect forwards the request received from the client to another URI. All the parameters sent with the original request will go with the forwarded request, they should not be added to the new URI.

Example 9.14. Example of forwarding a request to the pulp.pdf page.


  <px:page name="bukowski">
    <px:show>
      <px:serverRedirect select="'/pages/pulp.pdf'"/>
    </px:show>
  </px:page>

px:show

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the response instruction.
refnoQNameA reference to a defined top-level px:show instruction.

Content

Optionally, a px:serializer element

A pipeline body.

Description

A px:show instruction defines a sequence of content generation, transform, filter and serialization steps that result in serialized output of some MIME type.

px:style

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the style resource.
refnoQNameA reference to a defined top-level px:style resource.
hrefyesURIThe URI of an XSLT stylesheet.
documentNSnons prefixIdentifies the namespace of documents to be looked up by the document URI resolver. Defaults to the namespace of the stylesheet.

Content

Examples

Example 9.15. Defining a style with reference to an XSLT file.


<px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
              ns="http://www.presentingxml.com/myapp">

  <px:style name="books" href="books/books.xsl"/>

</px:resources>

See also

px:systemContent

Attributes

NameMand.ValueDescription
namenoNCNameThe name of the content resource.
hrefnoURIThe URI of an XML document.

Content

    Examples

    Example 9.16. Defining a document with reference to an XML file.

    
    <px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
                  ns="http://www.presentingxml.com/myapp">
    
      <px:systemContent name="countries" href="books/countries.xml"/>
    
    </px:resources>
    
    

    px:transform

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the transform instruction.
    refnoQNameA reference to a defined top-level px:transform instruction.

    Content

    Examples

    Example 9.17. Transforming the books XML document with the books XSLT stylesheet.

    
      <px:page name="books">
        <px:parameter ns="" name="category"/>
        <px:show>
          <px:transform>
            <px:style ref="myapp:books"/>
            <px:content ref="myapp:books"/>
          </px:transform>
        </px:show>
      </px:page>
    
    

    See also

    px:validateRequest

    Attributes

    NameMand.ValueDescription

    Content

    A px:page element.

    Description

    The gatekeeper element supports invoking a page to validate a request.

    Examples

    See px:app.

    px:when

    Attributes

    NameMand.ValueDescription
    testyesExpressionThe boolean expression to evaluate.

    Content

    A pipeline body.

    Optional Module Reference

    Chapter 10. Flat File Module

    This appendix provides an alphabetical list of the elements that may appear as content in a px:flatFileContent instruction.

    px:commentSymbol

    Attributes

    NameMand.ValueDescription
    valueyesStringThe value of a comment symbol.

    Content

    None.

    px:field

    Attributes

    NameMand.ValueDescription
    nameyesNCNameThe name of the field.
    offsetnonumberFor positional fields, the zero based offset of the field in the record. If it is not specified and the field is fixed width, it defaults to one past the last character of the previous field (including its field delimiter, if any.)
    widthnonumberFor fixed width fields, the width of the field.
    trimno"yes" or "no"Indicates whether to trim leading and trailing whitespace. The default is yes
    trimLeadingno"yes" or "no"Indicates whether to trim leading whitespace. The default is yes
    trimTrailingno"yes" or "no"Indicates whether to trim trailing whitespace. The default is yes
    quoteno"yes" or "no" Indicates whether a value may be enclosed in quote marks, where the enclosing quote marks serve to delimit the value but are not part of the value itself. This allows the value to contain a field delimiter. The default is no.
    justifyno"left","right", or "center" When serializing XML to a flat file, for fixed width fields, indicates how to align the data within the field. The default is "left".
    padCharacternoCharacter When serializing XML to a flat file, for fixed width fields, specifies the character to pad the field, e.g., a space or zero. The default is a space.

    Content

    Optionally, a px:fieldAttributeMap element.

    Optionally, one or more px:fieldDelimiter elements. If it is not specified, it defaults to the field delimiter specified in the px:record element, if there is one. If none is specified and there is no default, and if this field is not the last field before a record delimiter, then the field must have fixed width and the width attribute must be specified.

    Notes

    • If you have a field value that includes a character that is the same as the quote symbol, you must escape that character. For example, if the quote symbol is the default double quotation mark, escaped by a second quote symbol, and if your record data is

      "Gun, with Occaisonal Music","""SHARP, FUNNY, VISIONARY"""
      
      then the values become
      Gun, with Occaisonal Music
      "SHARP, FUNNY, VISIONARY"
      

    px:fieldDelimiter

    Attributes

    NameMand.ValueDescription
    valueyesStringA string of one or more characters that indicates the end of a field.

    Content

    None.

    Description

    The field delimiter indicates the end of the field value. It is excluded from the field value. It may be one or more characters in length.

    The following special encodings may appear in a delimiter value.

    • \t, to indicate a tab.
    • \r, to indicate a carriage return.
    • \n, to indicate a line feed.

    Notes

    • If you have a field value that includes a character that is the same as the delimiter, you must define the field to have quoted field values and enclose the value of the field in quotes.

    px:fileHeader

    Attributes

    NameMand.ValueDescription
    linesyesNumberThe number of lines in the header.

    px:fileLayout

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the page.
    refnoQNameA reference to a defined top-level px:fileLayout resource.

    Content

    Examples

    See px:flatFileContent

    px:flatFileContent

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the page.
    hrefnoURIThe URI of a flat file.

    Content

    Examples

    Example 10.1. Example of Comma Separated Value (csv) file content.

    
      <px:flatFileContent name="countries" href="books/countries.csv">
        <px:fileLayout>
          <px:record>
            <px:fieldDelimiter value=","/> 
            <px:field name="countryCode"/>
            <px:field name="countryName" quote="yes"/>
          </px:record>
        </px:fileLayout>
        <px:recordSetMapping>
          <countries>
            <px:recordMapping>
              <country>
                <px:fieldAttributeMap name="countryCode" attribute="countryCode"/>
                <px:fieldElementMap name="countryName" element="countryName"/>
              </country>  
            </px:recordMapping>
          </countries>
        </px:recordSetMapping>  
      </px:flatFileContent>
    
    

    Suppose the flat file countries.csv contains the lines

    
    ATF,"FRENCH SOUTHERN TERRITORIES, D.R. OF"
    VUT,VANUATU
    WLF,WALLIS & FUTUNA ISLANDS
    
    
    Then the document named "countries" will have the following XML representation:
    
    <countries>
      <country countryCode="ATF">
        <countryName>FRENCH SOUTHERN TERRITORIES, D.R. OF</countryName>
      </country>
      <country countryCode="VUT">
        <countryName>VANUATU</countryName>
      </country>
      <country countryCode="WLF">
        <countryName>WALLIS &amp; FUTUNA ISLANDS</countryName>
      </country>
    </countries>
    
    

    Example 10.2. Example of Java properties file content.

    
      <px:flatFileContent name="messages" href="messages.properties">
        <px:fileLayout>
          <px:commentSymbol value="#"/>
          <px:record>
            <px:fieldDelimiter value=","/> 
            <px:field name="name"/>
            <px:field name="value" quote="yes"/>
          </px:record>
        </px:fileLayout>
        <px:recordSetMapping>
          <messages>
            <px:recordMapping>
              <px:fieldElementMap name="name" element="message">
                <px:fieldAttributeMap name="value" attribute="key"/>
              </px:fieldElementMap>
            </px:recordMapping>
          </messages>
        </px:recordSetMapping>  
      </px:flatFileContent>
    
    

    Suppose the properties file messages.properties contains the lines

    
    parser.next.1=A character is required after \\.
    parser.next.2='?' is not expected.  '(?:' or '(?=' or '(?!' or '(?<' or '(?#' or '(?>'?
    #parser.next.3='(?<=' or '(?<!' is expected.
    parser.next.4=A comment is not terminated.
    
    
    Then the document named "messages" will have the following XML representation:
    
    <messages>
      <message key="parser.next.1">A character is required after \\.</message>
      <message key="parser.next.2">'?' is not expected.  '(?:' or '(?</message>
      <message key="parser.next.4">A comment is not terminated.</message>
    </messages>
    
    

    px:flatFileSerializer

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the page.

    Content

    Examples

    Example 10.3. Example of a serializer producing Comma Separated Value (csv) files.

    
    <px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
                  xmlns:myapp="http://www.presentingxml.com/myapp"                   
                  ns="http://www.presentingxml.com/myapp">
      
      <px:page name="countries">                         
        <px:show>
          <px:flatFileSerializer>
            <px:fileLayout ref="myapp:countriesFileLayout"/>
            <px:recordSetMapping ref="myapp:countriesFileMapping"/>
          </px:flatFileSerializer>
          <px:transform>
            <px:systemContent href="documents/countries.xml"/>
          </px:transform>
        </px:show>
      </px:page>
      
      <px:fileLayout name="countriesFileLayout">
        <px:commentSymbol value="#"/>
        <px:record>
          <px:fieldDelimiter value=","/>
          <px:quoteSymbol value='"' escapedBy="\"/>
          <px:field name="code"/>
          <px:field name="name" quote="yes" trimLeading="yes"/>
        </px:record>
      </px:fileLayout>      
      
      <px:recordSetMapping name="countriesFileMapping">
        <countries>
          <px:recordMapping>
            <country>
              <px:fieldElementMap field="name" element="countryName"/>  
              <px:fieldAttributeMap field="code" attribute="countryCode"/>
            </country>  
          </px:recordMapping>
        </countries>
      </px:recordSetMapping>  
    
    </px:resources>
    
    

    Suppose the input XML file countries.xml contains the lines

    
    <?xml version="1.0" encoding="utf-8"?>
    <countries>
      <country countryCode="ATF">
        <countryName>FRENCH SOUTHERN TERRITORIES, D.R. OF</countryName>
      </country>    
      <country countryCode="DEU">
        <countryName>GERMANY, FEDERAL REPUBLIC OF</countryName>
      </country>
    </countries>
    
    
    Then the output csv file countries.csv will look like:
    
    ATF,"FRENCH SOUTHERN TERRITORIES, D.R. OF"
    DEU,"GERMANY, FEDERAL REPUBLIC OF"
    
    

    px:quoteSymbol

    Attributes

    NameMand.ValueDescription
    valuenoCharacterThe symbol to optionally enclose field values. Defaults to the double quotation mark.
    escapedBynoCharacterThe symbol used to escape the quote symbol, e.g. the backslash ('\') or the quote symbol itself. Defaults to the quote symbol.

    Content

    None.

    Description

    This instruction defines the character that is used to enclose field values.

    px:record

    Attributes

    NameMand.ValueDescription

    Content

    Optionally, one or more px:recordDelimiter elements. The default is two possible delimiters: a linefeed, or a carriage return followed by a linefeed.

    When serializing XML to a flat file, if more than one record delimiter has been defined, the serializer checks to see if one of the delimiters matches the system conventional end-of-line character. If so, it uses that one, otherwise it uses the first one.

    Optionally, a px:quoteSymbol element.

    Optionally, one or more px:fieldDelimiter elements.

    One or more px:field elements.

    px:recordDelimiter

    Attributes

    NameMand.ValueDescription
    valueyesStringA string of one or more characters that indicates the end of a record.

    Content

    None.

    Description

    The record delimiter indicates the end of the record.

    The following special encodings may appear in a delimiter value.

    • \t, to indicate a tab.
    • \r, to indicate a carriage return.
    • \n, to indicate a line feed.

    px:recordMapping

    Attributes

    None

    Chapter 11. SQL Module

    This appendix provides an alphabetical list of the elements that may appear as content in a px:sqlContent instruction.

    px:jdbcConnectionPool

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the JDBC connection pool.
    driveryesJava classThe class name of the JDBC driver.
    databaseURLyesURLThe JDBC database URL.
    useryesStringThe database user name.
    passwordyesStringThe database password.
    minConnectionsnoNumberThe minimum number of connections to keep in the pool. The default is zero.
    maxConnectionsnoNumberThe maximum number of connections to keep in the pool. The default is any number.
    testStatementnoStringA statement to test the liveness of the database before obtaining a connection.

    Content

    None.

    px:sqlContent

    Attributes

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the JDBC connection pool.

    Content

    Examples

    Example 11.1. Example of SQL Content.

    
    <px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
                  xmlns:myapp="http://www.presentingxml.com/myapp"                   
                  ns="http://www.presentingxml.com/myapp">
      
      <px:page name="employees">                         
        <px:show>
          <px:content ref="myapp:employees"/>
        </px:show>
      </px:page>
      
      <px:jdbcConnectionPool name="jdbc-pool"
                             driver="oracle.jdbc.driver.OracleDriver"
                             databaseURL="jdbc:oracle:thin:@127.0.0.1:1521:dev"
                             user="scott"
                             password="dev"
                             minConnections="2"
                             testStatement="SELECT * FROM DUAL"/>
                             
      <px:sqlContent name="employees"> 
        <px:jdbcConnectionPool ref="myapp:jdbc-pool"/>
        <px:sqlQuery>       
          SELECT EMPNO, ENAME AS NAME,JOB FROM EMP WHERE JOB = '{$job}' 
        </px:sqlQuery>       
        <px:recordSetMapping>
          <employees>
            <px:recordMapping>
              <employee>
                <px:fieldAttributeMap field="EMPNO" attribute="employee-no"/>  
                <px:fieldElementMap field="NAME" element="name"/>  
                <px:fieldElementMap field="JOB" element="job"/>
              </employee>  
            </px:recordMapping>
          </employees>
        </px:recordSetMapping>  
      </px:sqlContent>
    
    </px:resources>
    
    

    When the page employees is requested with the parameter job=action, the result is the following XML document:

    
    <?xml version="1.0" encoding="utf-8"?>
    <employees>
      <employee employee-no="7788">
        <name>SCOTT</name>
        <job>ANALYST</job>
      </employee>
      <employee employee-no="7902">
        <name>FORD</name>
        <job>ANALYST</job>
      </employee>
    </employees>
    

    px:sqlQuery

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the JDBC connection pool.

    Content

    Examples

    See px:sqlContent

    Chapter 12. SUN Multi Schema Validator Module

    This appendix provides an alphabetical list of the elements that may appear as content in a px:msvFilter instruction.

    px:msvFilter

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the filter.
    schemanoURIThe location of the schema document.

    Examples

    Example 12.1. Validating the countries document.

    
    <px:resources xmlns:px="http://www.presentingxml.com/PresentingXML"
                  ns="http://www.presentingxml.com/myapp">
    
      <px:page name="countries">
        <px:show>
          <px:transform>
            <px:msvFilter schema="data/countries.xsd"/>
            <px:content ref="myapp:countries"/>
          </px:transform>
        </px:show>
      </px:page>
    
      <px:systemContent name="books" href="books/countries.xml"/>
    
    </px:resources>
    
    

    Chapter 13. FOP Module

    This appendix provides an alphabetical list of the elements that may appear as content in a px:fopSerializer instruction.

    px:fopSerializer

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the serializer.

    Content

    None.

    Examples

    Example 13.1. Defining an Apache fop serializer.

    
      <px:fopSerializer/>
    
    

    Example 13.2. Serializing an xsl-fo XML tree with an Apache fop serializer to produce pdf.

    
      <px:page name="pulp">
        <px:show>
          <px:fopSerializer/>
          <px:transform>
            <px:style ref="myapp:novel-fo"/>
            <px:content ref="myapp:pulp"/>
          </px:transform>
        </px:show>
      </px:page>
    
    

    Chapter 14. Mail Module

    This appendix provides an alphabetical list of the elements that may appear as content in the px:mailAccount and px:sendMail instructions.

    px:attachment

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the response instruction.

    Content

    Optionally, a px:serializer element

    A pipeline body.

    Description

    A px:attachment instruction defines a sequence of content generation, transform, filter and serialization steps that result in serialized output of some MIME type as an attachment to a message.

    px:mailAccount

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the mail account.
    smtpHostyeshostThe smtp host.

    Content

    px:sender

    Examples

    Example 14.1. Defining a mail account.

    
      <px:mailAccount name="my-account" 
                      smtpHost="changeme"> 
        <px:sender displayName="changeme" emailAddress="changeme"/>
      </px:mailAccount>
    
    

    px:message

    Attributes

    None.

    Content

    • Optionally, a text body.
    • Optionally, one or more px:part elements.
    • Optionally, one or more px:attachment elements.
    itemizedlist>

    px:part

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the response instruction.
    typenotype codeThe type of a part. The only allowed value is "alternative"

    Content

    Optionally, a px:serializer element

    A pipeline body.

    Description

    A px:part instruction defines a sequence of content generation, transform, filter and serialization steps that result in serialized output of some MIME type in the body of a message.

    px:sender

    Attributes

    NameMand.ValueDescription
    displayNamenoNCNameThe display name for the owner of the account.
    emailAddessyesaddressThe email address of the sender.

    Content

    None.

    px:sendMail

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the mail sender.
    subjectyesTextThe subject of the message.
    toyesaddressesA comma separated list of email addresses of recipients.
    ccyesaddressesA comma separated list of email addresses of recipients.

    Content

    itemizedlist>

    Examples

    Example 14.2. Mail example.

    
        
      <px:page name="books/html">
        <px:parameter ns="" name="category"/>
        
        <px:sendMail subject="test" 
                     to="changeme"
                     cc="changeme">
          <px:mailAccount ref="myapp:my-account"/>
          <px:message>
            <px:part>
              <px:transform>           
                <px:style ref="myapp:welcome/html"/>
              </px:transform>        
            </px:part>
            <px:attachment filename="pulp.pdf">
              <px:fopSerializer/>
              <px:transform>
                 <px:style ref="myapp:novel/fo"/>
                 <px:content ref="myapp:pulp"/>
              </px:transform>
            </px:attachment>      
          </px:message>
        </px:sendMail> 
    
    

    Chapter 15. Stream Filter Module

    The px:streamFilter instruction provides a way of filtering a stream of XML content in a pipeline without requiring the construction of a tree representation of the document. The input into the filter is a sequence of SAX events and the output is a sequence of SAX events. The events allowed into the filter are restricted by a match expression, using the in attribute, and the events allowed out of the filter are restricted by another match expression, using the out attribute. Within the body of the filter, the nodes flowing through the stream may be updated, removed, and given new siblings or children.

    This chapter provides an alphabetical list of the elements that may appear as content in a px:streamFilter instruction.

    px:appendChild

    Attributes

    None.

    Content

    An insert body.

    Description

    Inserts content as a child of the current node. The new child is inserted after the last child of the current node.

    See also

    px:input

    Attributes

    NameMand.ValueDescription
    matchyesSAXMatchExprA pattern that determines which elements go into the filter. Matching is on element names and attribute names and values (see example below.) If an element is matched, all of its children are also matched.

    Content

    None

    See also

    px:insertSiblingAfter

    Attributes

    None.

    Content

    An insert body.

    Description

    Inserts content as the immediately following sibling of the current node.

    See also

    px:insertSiblingBefore

    Attributes

    None.

    Content

    An insert body.

    Description

    Inserts content as the immediately preceding sibling of the current node.

    See also

    px:output

    Attributes

    NameMand.ValueDescription
    matchnoSAXMatchExprA pattern that determines which elements come out of the filter. Matching is on element names and attribute names and values (see example below.) If an element is matched, all of its children are also matched. The default is all elements.

    Content

    None

    See also

    px:remove

    Attributes

    None.

    Content

    None.

    Description

    Removes the current node.

    See also

    px:streamFilter

    Attributes

    NameMand.ValueDescription
    namenoNCNameThe name of the page.

    Content

    • Optionally, a px:input element to restrict input into the filter. The default is all elements.
    • Optionally, a px:output element to restrict output from the filter. The default is all elements.

    Any number of the following elements:

    Examples

    Examples of SAXMatchExpr expressions.

    • "title | author"
    • ".[cat='X' or cat='F']"
    • "book[cat='X' or cat='F']"
    • "book[cat='X' and tax=0.15]"
    • "book[cat='X' and price &gt; 5.0]"

    The three examples below all produce the same output.

    Example 15.1. Adding the title Small Holdings to the Books HTML page with three transform steps.

    
      <px:page name="books">
        <px:show>
          <px:transform> 
            <px:style ref="myapp:books"/> 
            <px:transform> 
              <px:streamFilter>
                <px:input match="books[@cat='F']"/>
                <px:appendChild>
                  <book><title>Small Holdings</title><author>Nicola Barker</author></book>>
                 </px:appendChild>
              </px:streamFilter>
              <px:content ref="myapp:books"/>
            </px:transform> 
          </px:transform> 
        </px:show>          
      </px:page>
    
    

    Example 15.2. Adding the title Small Holdings to the Books HTML page with two transform steps.

    
      <px:page>
        <px:show>
          <px:transform> 
            <px:streamFilter>
              <px:input match="books[@cat='F']"/>
              <px:appendChild>
                <book><title>Small Holdings</title><author>Nicola Barker</author></book>>
               </px:appendChild>
            </px:streamFilter>
            <px:style ref="myapp:books"/>
            <px:content ref="myapp:books"/>
          </px:transform> 
        </px:show>          
      </px:page>
    
    

    Example 15.3. Adding the title Small Holdings to the Books HTML page with one transform step.

    
      <px:page name="books">
        <px:show>
          <px:transform> 
            <px:streamFilter">
              <px:input match="books[@cat='F']"/>
              <px:appendChild>
                <book><title>Small Holdings</title><author>Nicola Barker</author></book>>
              </px:appendChild>
            </px:streamFilter>
            <px:style ref="myapp:books"/>
            <px:content ref="myapp:books"/>
          </px:transform> 
        </px:show>          
      </px:page>
    
    

    px:update

    Attributes

    NameMand.ValueDescription
    searchFornostringSearch for occurance of string.
    replaceWithyesstring Replace occurance of searchFor string. If no searchFor string is specified, replace the entire element value.
    elementsnoWhitespace-separated list of NameTestsDefines the elements within the filter whose text nodes are to be updated.
    attributesnoWhitespace-separated list of NameTestsDefines the attributes within the filter whose values are to be updated.

    Content

    None.

    Description

    Updates the current node.

    Examples

    Example 15.4. Update example 1.

    
      <px:page name="books">
        <px:show>
          <px:transform> 
            <px:streamFilter>
              <px:input match="*"/>
              <px:update attributes="cat" searchFor="F" replaceWith="C"/>
            </px:streamFilter>
            <px:style ref="myapp:books"/>
            <px:content ref="myapp:books"/>
          </px:transform> 
        </px:show>          
      </px:page>
    
    

    This example checks the values of all attributes named "cat" and replaces occurances of "F" with "C".

    Examples

    Example 15.5. Update example 2

    
      <px:page name="books">
        <px:show>
          <px:transform> 
            <px:streamFilter>
              <px:input match="*[@cat='F']"/>
              <px:update replaceWith="C"/>
            </px:streamFilter>
          </px:transform> 
          <px:style ref="myapp:books"/>
          <px:content ref="myapp:books"/>
        </px:show>          
      </px:page>
    
    

    This example checks the values of all attributes named "cat" that have the value "F" and substitutes "C".

    See also

    px:variable

    Attributes

    NameMand.ValueDescription
    nameyesQNameThe name of the variable.
    valueyesSAXValueExprThe value of the variable. The string value may contain one or more SAXValueExprs enclosed within curly braces, e.g. "{lastName},{firstName}".

    Content

    None.

    Description

    Defines a local variable value within the scope of the filter.

    Appendix A. Building the Source Distribution

    Ant

    Ant is used for building the Presenting XML source. Ant is an open source java-based build tool. It specifies an XML format for projects. It is cross-platform.

    A version of ant is included with the Presenting XML distribution files, in the lib/ant directory. You can obtain the latest version of Ant from the Jarkarta web site http://jakarta.apache.org/site/binindex.html

    Building Presenting XML

    An ant build.xml file is located in the presentingxml directory. To build the distribution jar file presentingxml.jar, enter the command

    build
    

    The build.xml file defines three build targets:

    • dist, the default, which builds the distribution jar file presentingxml.jar in the lib directory.

    • tests, which builds the test suite jar file tests.jar in the tests directory.

    • javadoc, which builds the javadoc files in the docs/api directory.

    To specify a target, provide the target name as an argument to the build command, e.g. to build the javadoc target, enter the command

    build javadoc
    

    The build requires the presence of certain third party jar files in the lib directory. These are described in a readme file in the lib directory.

    Appendix B. Configuring Tomcat

    You will need to configure your web server to work with Presenting XML. This section describes how to do that for Jakarta Tomcat.

    The distribution files for the Jakarta Tomcat web server may be obtained from http://jakarta.apache.org/site/binindex.html.

    Configuring Tomcat Version 4.0

    Presenting XML may be deployed in Tomcat in a number of ways, by pointing the document root of the web application to an unpacked directory hierarchy in the development source tree, or by copying an application archive file into the $CATALINA_HOME/webapps directory.

    Deploying in the development source tree

    The steps to configure Jakarta Tomcat to work with Presenting XML are as follows:

    • Edit the server.xml file in the tomcat conf directory. Add the following Context element in the server.xml file (changing docBase as appropriate):

      
        <Context path="/bookstore" 
          docBase="C:/Projects/presentingxml/webapps/bookstore" 
          crossContext="false"
          debug="0" 
          reloadable="true" > 
        </Context>
      
      

    • Set the environmental variable JAVA_HOME to a version of the jdk 1.3 or above, i.e.

      set JAVA_HOME=C:\tools\java\jdk1.3.1
      
      (changing C:\tools as appropriate), or add the above line to the top of the startup.bat file (tomcat.sh for Unix) in the jakarta tomcat bin directory.

    You will need to restart Tomcat to have the changes in the server.xml file take effect.

    Deploying a Web Application aRchive (WAR) file.

    The steps to configure Jakarta Tomcat to work with Presenting XML are as follows:

    • Create the web application archive file. From the web application directory, e.g. webapps/bookstore, run the following command:

      jar cf ../bookstore.war *
      

    • Edit the server.xml file in the tomcat conf directory. Add the following Context element in the server.xml file (changing docBase as appropriate):

      
        <Context path="/webapps/bookstore" 
          docBase="/bookstore" 
          crossContext="false"
          debug="0" 
          reloadable="true" > 
        </Context>
      
      

    • Set the environmental variable JAVA_HOME to a version of the jdk 1.3 or above, i.e.

      set JAVA_HOME=C:\tools\java\jdk1.3.1
      
      (changing C:\tools as appropriate), or add the above line to the top of the startup.bat file (tomcat.sh for Unix) in the jakarta tomcat bin directory.

    You will need to restart Tomcat to have changes in the server.xml file take effect.

    Configuring Tomcat Versions 3.x

    The steps to configure Jakarta Tomcat 3.x to work with Presenting XML are as follows:

    • Edit the server.xml file in the tomcat conf directory. Add the following Context element in the server.xml file (changing docBase as appropriate):

        <Context path="/bookstore" 
          docBase="C:\Projects\presentingxml\webapps\bookstore" 
          crossContext="false"
          debug="0" 
          reloadable="true" > 
        </Context>
      

    • Set the environmental variable JAVA_HOME to a version of the jdk 1.3 or above, i.e.

      set JAVA_HOME=C:\tools\java\jdk1.3.1
      
      (changing C:\tools as appropriate), or add the above line to the top of the startup.bat file (tomcat.sh for Unix) in the jakarta tomcat bin directory.

    • Delete jaxp.jar and parser.jar in the tomcat lib directory, replace them with xerces.jar (from the presentingxml/lib directory), and modify the config file workers.properties, replacing

      worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)jaxp.jar
      worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)parser.jar
      
      with
      worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)xerces.jar
      

    Appendix C. Adapters

    Transformer Adapters

    Changing between Saxon and Xalan

    In the sample bookstore web application, the steps to switch from the saxon transformer to the xalan transformer are as follows:

    • In the config subdirectory, open the presentingxml.xml file. Locate the px:transformer element shown below.

      
        <px:transformer className="com.icl.saxon.TransformerFactoryImpl">
          <px:outputProperties>
            <px:property name="indent" value="no"/>
            <px:property name="{http://icl.com/saxon}omit-meta-tag" value="yes"/>
          </px:outputProperties>
        </px:transformer>
      
      
      Comment out the px:transformer defined for saxon (shown above) and uncomment the px:transformer defined for xalan.

    • In the build subdirectory, edit the build.properties file. Comment out the line below # saxon lib list and uncomment the line below # xalan lib list.

    • In the build subdirectory, rebuild the sample web application by entering build at the command prompt.

    Appendix D. System Configuration Reference

    This appendix provides an alphabetical list of all the elements that may appear in a system configuration script.

    px:cacheManager

    Attributes

    None.

    Content

    Optionally, a px:properties element.

    px:config

    Attributes

    None.

    Content

    px:device

    Attributes

    NameMand.ValueDescription
    nameyesStringThe name of a device.
    acceptnoComma-separated listList of MIME types accepted by the device.

    Content

    None.

    px:deviceMap

    Attributes

    NameMand.ValueDescription
    searchyesRegular expression patternSearches for a pattern in the User-Agent to identify a device.
    deviceyesNameIdentifies a device.

    Content

    None.

    px:devices

    Attributes

    None.

    Content

    Zero or more px:device elements.

    Zero or more px:deviceMap elements.

    px:documentBuilder

    Attributes

    NameMand.ValueDescription
    classNamenoJava ClassAn implementation of the jaxp javax.xml.parsers.DocumentBuilderFactory class.

    Content

    Optionally, a px:systemProperties element.

    px:logger

    Attributes

    NameMand.ValueDescription
    classNameyesStringA class that implements com.presentingxml.tools.system.Logger.

    Content

    None.

    px:outputProperties

    Attributes

    None.

    Content

    One or more px:property elements.

    px:patternMatcher

    Attributes

    NameMand.ValueDescription
    classNameyesJava ClassAn implementation of the com.presentingxml.tools.patternmatcher.PatternMatcher interface.

    Content

    None.

    px:properties

    Attributes

    None.

    Content

    One or more px:property elements.

    px:property

    Attributes

    NameMand.ValueDescription
    nameyesStringThe name of a property.
    valueyesStringThe value of a property.

    Content

    None.

    px:saxParser

    Attributes

    NameMand.ValueDescription
    classNamenoJava ClassAn implementation of the jaxp javax.xml.parsers.SAXParserFactory class.

    Content

    Optionally, a px:systemProperties element.

    px:systemProperties

    Attributes

    None.

    Content

    One or more px:property elements.

    px:transformer

    Attributes

    NameMand.ValueDescription
    classNamenoJava ClassAn implementation of the jaxp javax.xml.transform.TransformerFactory class.

    Content

    Optionally, a px:outputProperties element.

    Optionally, a px:systemProperties element.

    Appendix E. Presenting XML Console App

    This appendix describes the Presenting XML console app.

    Starting Presenting XML as a standalone console application

    The following software must be installed:

    • Java JDK 1.3 or later (it will not work with earlier versions.)

    • The third party libraries that come with the Presenting XML distribution (the servletapi jar file is not needed.)

    • An application jar file that contains the custom error handler and requestListener implementations.

    The java class com.presentingxml.presenter.consoleapp.ConsoleApp has a main program that may be used to generate pages based on the resources script. The form of the command is

    
    java -classpath <jar files> com.presentingxml.presenter.consoleapp.ConsoleApp 
    [options] page {param=value}...
    
    

    The options are as follows:

    -c

    Overrides the default system configuration file. The default is the presentingxml.xml file in the presentingxml resources directory, which is included in the presentingxml.jar file.

    -r

    Identifies the resources script.

    -a

    Indicates the desired MIME type of the output, or a comma separated list if more than one is acceptable. The default is "text/html".

    -o

    Identifies the output file. The default is standard out.

    From an app directory, e.g. the sample webapps/bookstore, you can use the simpler expression

      java -jar WEB-INF\lib\bookstore.jar [options] page {param=value}...
    

    The syntax for generating the default (HTML) books page is as follows:

    
        java -jar WEB-INF\lib\bookstore.jar -c config\presentingxml.xml -r pages\pages.xml 
          -o books.html /bookstore/pages/books
    
    

    The syntax for generating the associated WML books page is:

    
        java -jar WEB-INF\lib\bookstore.jar -c config\presentingxml.xml -r pages\pages.xml 
          -o books.wml  -a text/vnd.wap.wml /bookstore/pages/books
    
    

    The syntax for generating the HTML file for computer books is:

    
        java -jar WEB-INF\lib\bookstore.jar -c config\presentingxml.xml -r pages\pages.xml 
          -o /bookstore/pages/books.html books category=C
    
    

    Glossary

    CSV

    Comma separated values (CSV).

    SAXMatchExpr

    SAXMatchExpr stands for "SAX match expression." An example is "author | title[@cat='F']." A SAX match expression restricts the flow of elements through a SAX filter. The syntax for a SAXMatchExpr is a small subset of the syntax for an XPath expression, including the parts that make sense for filtering on the startElement event, with just the current element name and the attributes accessible.

    Examples of SAXMatchExpr expressions.

    • "title | author"
    • ".[cat='X' or cat='F']"
    • "book[cat='X' or cat='F']"
    • "book[cat='X' and tax=0.15]"
    • "book[cat='X' and price &gt; 5.0]"

    SAXValueExpr

    SAXValueExpr stands for "SAX value expression." An example is "@category"

    Insert Body

    A sequence of literal result elements and px:transform instructions forming the content of a px:insertSiblingAfter, px:insertSiblingBefore, or px:appendChild element.

    Mime Type

    The Multipurpose Internet Mail Extension (MIME) type provided by the server and used by the browser to identify the type of document.

    NameTests

    A NameTest may be a name, the symbol "*", which stands for any name, or the expression "prefix:*" which represents all names in the specified namespace.

    NCName

    NCName stands for "no colon name." An example is "books."

    QName

    QName stands for "qualified name." An example is "myapp:books."

    Top Level Element

    A top level element is an element that appears as an immediate child of px:resources.

    Uniform Resource Identifier

    A short string that stands for the name or address of a resource.