[html]

XPath Datatypes & Functions, Using Ant, and XSLT in Web Applications

R. Alexander Milowski

milowski at sims.berkeley.edu

#1

Datatypes

#2

Functions

#3

Functions - Nodes

#4

Functions - Strings

#5

Functions in General

#6

String Manipulation

#7

Strings and xsl:value-of

#8

Numbers

#9

Number Formatting

#10

Identifiers

#11

Language

#12

Multiple Input Documents

#13

Base URI & document()

#14

Aggregation Example

#15

Using Ant to Apply XSLT

#16

The Basic Ant File

#17

The Ant Concept

#18

The XSLT Task

#19

XSLT in Web Applications

#20

Structuring a Web Application

#21

Setting Up a Web Project in Netbeans

  1. Choose the File->New Project menu item.

  2. Select 'Web' in the project 'Categories' panel and 'Web Application' from the 'Projects' panel and then click on 'Next'.

  3. Choose a project name.

  4. You may change the project location. If you leave the 'Project Folder' input alone, it will concatenate the name and the location together to make the project folder.

  5. Click on 'Finish'.

#22

The Basic web.xml File

#23

Using Filters to Style with XSLT

#24

Two Necessary Steps

  1. The supporting libraries need to be added to your project:

    1. Create a 'lib' directory in your 'WEB-INF' folder.

    2. Copy the 'jaxp.jar' from the website into that folder.

  2. Add the filter to the web.xml file--see next slide.

#25

Filter Configuration

Add this element to the web.xml file:

<filter>
    <filter-name>StaticXSLT</filter-name>
    <filter-class>com.milowski.jaxp.XSLTFilter</filter-class>
    <init-param>
       <param-name>content-type</param-name>
       <param-value>application/xhtml+xml</param-value>
    </init-param>
    <init-param>
       <param-name>reload</param-name>
       <param-value>yes</param-value>
    </init-param>
    <init-param>
       <param-name>static-extensions</param-name>
       <param-value>xml</param-value>
    </init-param>
    <init-param>
       <param-name>extensions</param-name>
       <param-value>xml,jsp</param-value>
    </init-param>
    <init-param>
       <param-name>stylesheet</param-name>
       <param-value>site.xsl</param-value>
    </init-param>
</filter>
    

#26

Filter Parameters

#27

Mapping the Filter

#28

Tweaking the Starting Document

#29

The Complete web.xml File

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 version="2.4">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>
            index.xml
        </welcome-file>
    </welcome-file-list>
    
    <filter>
       <filter-name>StaticXSLT</filter-name>
       <filter-class>com.milowski.jaxp.XSLTFilter</filter-class>
       <init-param>
       <param-name>content-type</param-name>
       <param-value>application/xhtml+xml</param-value>
       </init-param>
       <init-param>
       <param-name>reload</param-name>
       <param-value>yes</param-value>
       </init-param>
       <init-param>
       <param-name>static-extensions</param-name>
       <param-value>xml</param-value>
       </init-param>
       <init-param>
       <param-name>extensions</param-name>
       <param-value>xml,jsp</param-value>
       </init-param>
       <init-param>
       <param-name>stylesheet</param-name>
       <param-value>site.xsl</param-value>
       </init-param>
    </filter>
    
    <filter>
       <filter-name>DynamicXSLT</filter-name>
       <filter-class>com.milowski.jaxp.XSLTFilter</filter-class>
       <init-param>
       <param-name>content-type</param-name>
       <param-value>application/xhtml+xml</param-value>
       </init-param>
       <init-param>
       <param-name>reload</param-name>
       <param-value>yes</param-value>
       </init-param>
       <init-param>
       <param-name>static-extensions</param-name>
       <param-value>xml</param-value>
       </init-param>
       <init-param>
       <param-name>extensions</param-name>
       <param-value>xml,jsp</param-value>
       </init-param>
    </filter>
    
    <filter-mapping>
    <filter-name>DynamicXSLT</filter-name>
    <url-pattern>/xslt-test.xml</url-pattern>
    </filter-mapping>
    
    <filter-mapping>
    <filter-name>StaticXSLT</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    
</web-app>