Skip to content

mdom/Plack-Middleware-TazXSLT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Plack::Middleware::TazXSLT - transform xml documents by applying xsl stylesheets on the fly

DESCRIPTION

Plack::Middleware::TazXSLT is an plack aware middleware that transforms xml documents by applying xsl stylesheets on the fly. It was developed to serve an replacement for the http://modxslt.org/ as its development seems stalled for a long time. When using the word replacement please keep in mind that it is not really a drop in alternative for modxslt, as it just implements a very basic subset of modxslts functionality.

Every time the plack backend return a response to Plack::Middleware::TazXSLT it checks if the response is successful, not a redirect, not a HEAD request, has content and is actually a xml document. If all that applies, it parses the xml document and applies the supplied stylesheet to it.

There are two way to communicate which stylesheet to use. If the response returned by the application contains the HTTP header X-Taz-XSLT-Stylesheet, it's value is expected to be an URL pointing to an XSLT stylesheet which is than downloaded and applied. If the response misses this header, Plack::Middleware::TazXSLT tries to find a processing instruction of type of text/xsl:

<?modxslt-stylesheet 
  type="text/xsl" 
  href="http://$HEADER[Host]/$HEADER[X-Taz-Base]/base.xsl" ?>

All occurrences of $HEADER[] in its href attribute are replaced the the values from the backends http response.

SYNOPSIS

my $app = builder {
  enable "TazXSLT";
  Plack::App::Proxy->new( backend => 'LWP', remote => 'http://example.com/ )->to_app;
};

ATTRIBUTES

user_agent

HTTP user agent to fetch the the necessary stylesheets. Defaults to an LWP::UserAgent with its timeout set to timeout seconds and act according to the environment variables HTTP_PROXY and HTTPS_PROXY.

It is possible to provide an useragent object of another class as long as it respond to a call of get and returns an object that provides the method calls is_redirect, is_success, content_length, content_length, content_is_xml and behaves semantically similar to LWPs HTTP::Reponse.

xml_parser

An instance of XML::LibXML. Defaults to the following simple call:

XML::LibXML->new();
xslt_parser

An instance of XML::LibXSLT. Defaults to the following simple call:

XML::LibXSLT->new();
name

A string with is accessible via the xslt variable modxslt-name. Defaults to tazxslt.

timeout

Timeout for http connections this objects user_agent attribute. Defaults to 180 seconds.

log_filter

A subroutine reference that is called with the error message as its only argument every time libxml is not able to parse the xml document. Unfortunately libxml returns multiline error messages with indentation. This defaults to the function parse_libxml_error that strips the string of all newlines and replaces consecutive whitespace characters into one space character.

ENVIRONMENT

TAZ_XSLT_PROFILE

If this environment variable is set to a true value, every call to apply_transformation is profiled and the result will be printed to wherever $env->{'psgi.errors'} is pointing.

[http://example.com] xslt-processing-time: 0.01245

SEE ALSO

http://modxslt.org/, https://metacpan.org/module/Plack::Middleware::XSLT

About

transform xml documents by applying xsl stylesheets on the fly

Resources

License

Stars

Watchers

Forks

Packages

No packages published