Book List Example

The XML file books.xml (derived from a file issued originally by Microsoft) is used for a number of demonstrations. This file, along with its DTD books.dtd, is found in the samples/data directory.

Transform

The stylesheet books.xsl can be used to display the data, and is designed to illustrate several Saxon extensions. Run this as follows, with the samples directory as the current directory:

On the Java platform:

java net.sf.saxon.Transform -s:data/books.xml -xsl:styles/books.xsl -o:output.html

On the .NET platform:

Transform -s:data/books.xml -xsl:styles/books.xsl -o:output.html

This produces an HTML page showing the data.

The stylesheet takes a parameter named "top-author". This is the name of the "author of the week", and the default value is "Jasper Fforde". To run the stylesheet with a different top author, try adding to the end of the command line:

..... top-author='Thomas Hardy'

Query

A query that runs with this data is also supplied. The command to use on the Java platform is:

java net.sf.saxon.Query -s:data/books.xml -q:query/books.xq -o:output.html

The equivalent on .NET is:

Query -s:data/books.xml -q:query/books.xq -o:output.html

Other demonstrations

Several other related XML resources are supplied. The schema for data/books.xml is data/books.xsd. Also supplied in the samples resources is the file data/books-invalid.xml, which (as the name suggests) is a version of the books file which is invalid against the schema, and data/more-books.xml which lists some different books. These resources may be used for instance with the sample applications QuickValidator.java, SchemaValidatorExample.java, and SchemaValidatorHandlerExample.java.

There is another stylesheet, styles/books-csv.xsl, which converts the data in the file data/books.xml into a comma-separated-values file.

The stylesheet styles/total.xsl is used by the JDOM2 Example application, and the query query/books-to-html.xq is used by one of the examples in the QueryAPIExamples.java application.

The sample program XPathExampleSA.java illustrates the use of the JAXP XPath API, extended by Saxon to allow schema-aware XPath 2.0 processing. The program is designed to run against the sample file books.xml. It produces a list of all books over 2cm thick that were published during the 6 years since the start of 2000.

Also see the SQL extension instructions example for details on the sample stylesheet styles/books-sql.xsl which uses Saxon SQL extension instructions to load the contents of books.xml into a database table.