Next Project ▶

XML: Schema and XSLT Transformations with a Complex Source

This was completed as a project for an XML course. The source file is relatively complex with many nested child nodes and attributes of different data types. It is meant to simulate data for a student exchange program. A schema and two transformations were designed for this source. The first transformation produces a styled HTML summary of the source. The second transformation produces formatted plain text. The links above will open the output for both transforms.

Show project.xml - The source document.

To validate the source a schema was required. The schema is relatively detailed with a lot of emphasis on required child elements and number of occurrences. For example, address elements must have one child element named either 'zip' or 'postalCode' each with it's own specific format. There must be a minimum of 2 'languagesSpoken' elements with no upper bound. Each 'languagesSpoken' element must have a 'fluency' attribute from 1 to 4. That's just a few of the details. Take a look at the code if you'd like to see more.

Show project.xsd - The schema for project.xml.

The HTML transformation does a couple of interesting things. It sorts and displays a concatenated name for each exchange element. For each exchange it lists the country choice with a priority of 1. The type attribute for each exchange is checked and the string 'Teacher' or 'Student' is substituted based on the value. At the bottom the count() function is used to tally the total number of teachers, students, and the combined total of both. The internal CSS was required for the project specific validation tool for the course.

Show project.xsl - The HTML transformation for project.xml.

The text transformation had to follow a very specific format. This was meant to simulate preparation of the data for use by some other process. Most numerical values are padded with zeros to the specified length. String values are padded with spaces. You'll see a template named 'pad_value' starting on line 145. It accepts 2 arguments; the value and desired length. This template is used to pad all string values with spaces and trim them to the specified length.

Show projectText.xsl - The text transformation for project.xml.

Next Project ▶