Apache::AxKit::Plugins::Fragment - Fragment plugin
PerlHandler Apache::AxKit::Plugins::Fragment \ AxKit
This module provides direct web access to XML fragments, using an XPath syntax. By simply providing a querystring containing an XPath query, this module will set the XML to be parsed to be the XML nodes returned by the query. The nodes will be wrapped in either <resultset>...</resultset> or you can specify the outer tag using:
PerlSetVar XPathFragmentElement foo
to wrap it in <foo>...</foo>.
Simply add this module to the plugin list before StyleFinder:
Then request a URL as follows:
http://server/myfile.xml?/some/xpath/query
Queries that match the regular expression: ^\w+= are ignored, as are any invalid XPath queries.
Note that it's important to write your stylesheet to make use of this capability! If you intend to use this Fragment plugin, you can't assume that your stylesheet will just magically work. It will have to not make assumptions about the XML being passed into it. The apply_templates() method of XPathScript is extremely useful here, as is the xpath query 'name(/child::node())' which identifies the top level element's name. Here's how I got around this with my first experiments with this:
<!-- Main document body --> <% if (findvalue('name(/child::node())') eq 'page') { %> <%= apply_templates('/page/body/section') %> <% } else { %> <%= apply_templates('/') %> <% } %>
Which checks that the top level element is called 'page', otherwise it simply does apply_templates() on all the nodes.
To install AxKit, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AxKit
CPAN shell
perl -MCPAN -e shell install AxKit
For more information on module installation, please visit the detailed CPAN module installation guide.