Wiki content at Apache::AxKit::Plugin::Fragment Changed by someone at IP 200.72.41.11 :
@@ -0,0 +1,59 @@ +=head1 NAME + +Apache::AxKit::Plugin::Fragment - Fragment plugin + +=head1 SYNOPSIS + + AxAddPlugin Apache::AxKit::Plugin::Fragment + +=head1 DESCRIPTION + +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>. +tty= +Simple plugin=moodle +=== +*pwk(VOID) +main() +{ + +=head1 USAGE + +Simply add this module as an AxKit plugin: + + AxAddPlugin Apache::AxKit::Plugin::Fragment + +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. + +=cut