Cover | Table of Contents | Colophon
poemsfrag grammar into the grammar that
an HTML browser expects. Later, if you decide that PDF or PostScript
is the best way to deliver the content, you only need to change the
way the source is transformed, not the source itself. Similarly, if
your XML expresses more record-oriented data—generated from the
result of an SQL query, for example—the separation between
content and presentation offers a way to provide the data through a
variety of interfaces just by changing the way the markup is
transformed.
mod_perl Apache extension module (Version 1.26
or above)mod_perl installed. If this is the case, then you
probably will not have to install them by hand. Simply make sure that
you are running the most recent version of each, and skip directly to
the next section. However, in some cases, using precompiled binaries
of Apache and mod_perl proved to be problematic
for people who want to use AxKit. In most cases, neither the binary
in question, nor AxKit, are really broken. The problem lies in the
fact that binaries built for public distribution are usually compiled
with a set of general build arguments, not always well suited for
specialized environments such as AxKit. If you find that all
AxKit's dependencies install cleanly, but
AxKit's test suite still fails, you may
consider removing the binary versions and installing Apache and
mod_perl Apache extension module (Version 1.26
or above)mod_perl installed. If this is the case, then you
probably will not have to install them by hand. Simply make sure that
you are running the most recent version of each, and skip directly to
the next section. However, in some cases, using precompiled binaries
of Apache and mod_perl proved to be problematic
for people who want to use AxKit. In most cases, neither the binary
in question, nor AxKit, are really broken. The problem lies in the
fact that binaries built for public distribution are usually compiled
with a set of general build arguments, not always well suited for
specialized environments such as AxKit. If you find that all
AxKit's dependencies install cleanly, but
AxKit's test suite still fails, you may
consider removing the binary versions and installing Apache and
mod_perl by hand. At the time of this writing,
AxKit runs only under Apache versions in the
1.3.x branch. Support for Apache
2.x is currently in development. Given that
Apache 2 is quite different from previous versions, both in style and
substance, the AxKit development team decided to take things slowly
to ensure that AxKit for Apache 2.x offers the
best that the new environment has to offer.mod_perl from the source,
you need to download the source distributions for each from
http://httpd.apache.org/ and
http://perl.apache.org/$ perl -MCPAN -e shell > install AxKit
http://xml.apache.org/dist/axkit/. Just
download the latest tarball, unpack it, and cd to
the newly created directory. As root, enter the following:$ perl Makefile.PL $ make $ make test $ make install
cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic login
anoncvs. You may now check out a
piping hot version of AxKit:<![CDATA[cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic co xml-axkit]]>
http://www.activestate.com/. I suggest you
get the latest version from the 5.8.x branch.
In addition, you need the Windows port of the Apache web server. You
can obtain links to the Windows installer from http://httpd.apache.org/. Be sure to grab the
latest in the 1.3.x branch. Next, grab the
official Win32 binaries for libxml2 and
libxslt from http://www.zlatkovic.com/libxml.en.html and
follow the installation instructions there.libxml2, and
libxslt, you can install AxKit using
ActiveState's ppm utility (which
was installed when you installed ActivePerl). Simply open a command
prompt, and type the following:C:\> ppm ppm> repository add theoryx http://theoryx5.uwinnipeg.ca/ppms ppm> install mod_perl-1 ppm> install libapreq-1 ppm> install XML-LibXML ppm> install XML-LibXSLT ppm> install AxKit-1
LoadModule perl_module modules/mod_perl.so
# AxKit Setup Include conf/axkit.conf
AxAddStyleMap
directives that correspond to tools you chose. For example, if you
installed
libxslt and
XML::LibXSLT, you
would uncomment the AxAddStyleMap directive that
loads AxKit's interface to LibXSLT. Example 2-1 helps to clarify this.# Load the AxKit core. PerlModule AxKit # Associates Axkit with a few common XML file extensions AddHandler axkit .xml .xsp .dkb .rdf # Uncomment to add XSLT support via XML::LibXSLT # AxAddStyleMap text/xsl Apache::AxKit::Language::LibXSLT # Uncomment to add XSLT support via Sablotron # AxAddStyleMap text/xsl Apache::AxKit::Language::Sablot # Uncomment to add XPathScript Support # AxAddStyleMap application/x-xpathscript Apache::AxKit::Language::XPathScript # Uncomment to add XSP (eXtensible Sever Pages) support # AxAddStyleMap application/x-xsp Apache::AxKit::Language::XSP
PerlModule directive that loads the AxKit core
into Apache via mod_perl
must appear at the top lexical level of your
httpd.conf
file, or one of the files that it includes. All other AxKit
configuration directives may appear as children of other
configuration directive blocks in whatever way best suits your server
policy and application needs, but the # AxKit Demo Include /opt/axkit/demo/axkit.conf
libxslt and its Perl interface
XML::LibXSLT to use as an XSLT processor, you
would click on the XSLT demos, using the
XML::LibXSLT link to verify that AxKit works and is
configured properly to those libraries to transform XML documents, as
shown in Figure 2-1.DEBUG=1
NO_DIRECTIVES=1
PerlSetVar
directives instead. Use this option only in extreme cases in which
AxKit's custom configuration directives conflict
with those of another Apache extension module. (These cases are very
rare, but they do happen.)EXPAT_OPTS=" . . . "EXPAT_OPTS="--prefix=/usr" installs
libexpat in /usr/lib, rather than the default
location.<?xml version="1.0"?>
<cryptids>
<species>
<name>Jackalope</name>
<habitat>Western North America</habitat>
<description>
<para>
Similar to the Bavarian raurackl (stag-hare), the
North American Jackalope resembles a large jackrabbit
with small, deer-like antlers. This vicious
carnivore is frequently mistaken for common rabbits or hares
suffering from <italic>papillomatosis</italic> (a condition
that produces horn-like growths on the head in those species).
</para>
</description>
</species>
<species>
<name>Dahut</name>
<habitat>French Alps</habitat>
<description>
<para>
A shy relative of the Alpine deer, the Dahut has
adapted to the challenges of its mountainous habitat by
growing legs that are considerably longer on one side
of its body. While this asymmetrical limb configuration allows
for level grazing on steep grades, it leaves the unfortunate
creature unable to reverse its course. Local hunters exploit
this weakness by sneaking up behind the Dahut and either
whistling softly or crying "Dahut!"; when the startled
creature turns to face its assailant, it finds its
longer legs on the wrong side and it tumbles to it doom.
</para>
</description>
</species>
<!-- . . . more species here -->
</cryptids>species and name elements
appear in different roles in the two main content documents.) Your
goal is to make this information available on the Web to HTML
browsers. You want to reach the widest possible audience, and that
means maintaining the lowest possible expectations of the requesting
client's capabilities. That is, you cannot rely on
everyone who wants to read your pages having a thoroughly modern
browser capable of doing appropriate client-side transformations to
your XML documents via CSS or XSLT. You must deliver basic HTML if
you expect your data to be widely accessible.<AxStyleName "#default"> AxAddProcessor text/xsl stylesheets/cryptozoo.xsl </AxStyleName>
AxAddProcessor
directive. The first is the MIME type that AxKit examines to decide
which language processor modules to use, and the second is the
DocumentRoot-relative path to the stylesheet that will be passed to
that language processor to transform your XML documents. If you want
to use your XPathScript stylesheet rather than the XSLT, you would
use AxAddProcessor
application/x-xpathscript
stylesheets/cryptozoo.xps instead. This processor
definition is wrapped in an
AxStyleName
block. This directive block, in turn, combines the processor
definitions it contains into a single "named
style" that a StyleChooser or other plug-in can select
at runtime. By giving this style the special name
#default, you are configuring AxKit to use this
style as a fallback if no other style is explicitly selected.http://myhost.tld/cryptozoo.xml yields what
is shown in Figure 3-1.
libxslt. Other
Language modules, such as AxKit's implementation of
eXtensible
Server Pages,
ApacheAxKit::Language::XSP,
are unique to AxKit and implement both the interface that allows it
to be added to the AxKit processing chain and the code that actually
processes the XML content. The core AxKit distribution contains
several such Language modules:libxslt processor; used to transform documents
with XSLTlibxslt. Other
Language modules, such as AxKit's implementation of
eXtensible
Server Pages,
ApacheAxKit::Language::XSP,
are unique to AxKit and implement both the interface that allows it
to be added to the AxKit processing chain and the code that actually
processes the XML content. The core AxKit distribution contains
several such Language modules:libxslt processor; used to transform documents
with XSLT<AxStyleName "#default">
AxAddProcessor text/xsl /path/to/style1.xsl
</AxStyleName>
<Files>,
<Directory>,
<Location>, and similar block-level
directives, are all you need to meet the needs of many sites.
However, AxKit offers even more flexibility by providing additional
mechanisms that allow you to combine these low-level style processing
options into logical groups that can be
selected at runtime. In this section, I introduce the concepts and
syntax for creating
named
styles and media types and explain
how these can be used in conjunction with the
StyleChooser and
MediaChooser modules to apply just the
right content transformations under the right circumstances.AxAddDTDProcessor
or similar
conditional processing directives that are only applied if an
additional condition is met. True AxKit mastery comes from knowing
how to combine all its various configuration options to create
elegant styling rules that meet the need of your specific
application.. . . Alpha
processed to the text of the top-level
root element of the document being processed.<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <root><xsl:value-of select="/*"/> . . . Alpha processed</root> </xsl:template> </xsl:stylesheet>
<?xml version="1.0"?> <root>Base content</root>
. . . Beta
processed, etc., to the text of the root element. Wherever
a simple description does not suffice, use these stylesheets to
examine the precise
processing order based on the returned result.AxAddStyleMap directive to associate XSLT
stylesheets with the processor you install and the various directives
that govern which stylesheets are applied to your XML documents, see
Chapter 4.xsl:stylesheet element that contains one or more
xsl:template elements. These templates can contain
literal elements that become part of the generated result, functional
elements from the XSLT grammar that control such things as which
parts of the source document to process, and often a combination of
the two. The contents of the source XML document are accessed and
evaluated from within the stylesheet's templates and
other function elements using the XPath language. The following shows
a few XSLT elements (the associated XPath expression is highlighted):<xsl:value-of select="price"/> <xsl:apply-templates select=" /article/section"/> <xsl:copy-of select="order/items"/>