XML::ApplyXSLT - convert XML data with XSLT stylesheet files |
XML::ApplyXSLT - convert XML data with XSLT stylesheet files
use XML::ApplyXSLT; $xapply = XML::ApplyXSLT->new;
# parse an XML document by various means $doc = $xapply->parse( $xml_filename ) || die $xapply->errorstring; $doc = $xapply->parse( \$xml_string ); $doc = $xapply->parse( \*FILEHANDLE );
# set global defaults, such as path, style, and class to lookup # stylesheets from the filesystem $xapply->config({ class => 'test', style => 'default' });
# load rules $xapply->rules( $rules_filehandle );
# determine information about a given document (via rules) ( $filedata, $defaults, $params ) = $xapply->study( $doc, $xml_filename );
# extra code here to mess with defaults, check parameters, etc.
# transform the previously parsed XML document via stylesheet found # via path, class, and style lookups ( $docref, $details ) = $xapply->transform( $doc, default => $defaults, param => $params); print $$docref;
This module converts XML documents with XSLT files. As different
stylesheets could be applied to a particular XML format depending on the
context, methods are provided to determine what class
and style
the XML data belongs to by DOCTYPE
, the root element name, or
Processing Instructions. The class
and style
information is used
to construct a path to a stylesheet file residing somewhere on the
filesystem, which is loaded and used to convert the XML data. The
class
and style
information can also be set manually, if only a
single stylesheet will be used.
Stylesheets are parsed and stored in memory to avoid reparsing the same stylesheet for multiple XML documents.
The XML::LibXML and XML::LibXSLT modules provide XML and XSLT parsing.
As this is a new module, the methods may change as more is learned about the needs of command line, CGI, or mod_perl based interfaces.
Looking at the code in t/1.t probably best bet for usage at this point.
%{keyword}
style statements in passed data against a hash of
lookup values. Used by get_style to expand the path
default to
find the location of the stylesheet to use.
output_as_bytes
method to produce the output document.
Rules are used to classify and set defaults and parameter values for XML documents, based on the XML document info. A rule is a single line, and may be extended by placing a backslash at the end of the line. Lines beginning with an octothorpe (#) will be ignored, as will blank lines. An example set of rules follow.
# set a default for everything defaults: path=/var/www/htdocs/xsl/%{class}/%{style}.xsl \ style=default
# when in specific subdirectory, alter path default dirname sub "site/example.org/htdocs" \ path=/var/www/site/example.org/htdocs/xsl/%{class}/%{style}.xsl
# handle different document types rootname eq "eolas" stop \ defaults: class=eolas \ params: request.preferred_style=%{style}
rootname eq "changelog" stop class=cvs2cl \ params: request.preferred_style=%{style}
doctype eq "-//OASIS//DTD DocBook XML V4.2//EN" stop class=docbook42
Newer versions of this module may be available from CPAN.
If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome.
No known issues, though see source for TODO and other comments.
AxKit, for more complex XML mangling needs.
The supporting modules XML::LibXML and XML::LibXSLT.
Jeremy Mates, <jmates@sial.org>
The author disclaims all copyrights and releases this module into the public domain.
XML::ApplyXSLT - convert XML data with XSLT stylesheet files |