[%#
# IMPORTANT NOTE
# This documentation is generated automatically from source
# templates. Any changes you make here may be lost.
#
# The 'docsrc' documentation source bundle is available for download
# from http://www.template-toolkit.org/docs.html and contains all
# the source templates, XML files, scripts, etc., from which the
# documentation for the Template Toolkit is built.
-%]
[% META book = 'Modules'
page = 'Plugin_XML_XPath'
%]
[% WRAPPER toc;
PROCESS tocitem
title ="SYNOPSIS"
subs = [];
PROCESS tocitem
title ="PRE-REQUISITES"
subs = [];
PROCESS tocitem
title ="DESCRIPTION"
subs = [];
PROCESS tocitem
title ="AUTHORS"
subs = [];
PROCESS tocitem
title ="VERSION"
subs = [];
PROCESS tocitem
title ="COPYRIGHT"
subs = [];
PROCESS tocitem
title ="SEE ALSO"
subs = [];
END
%]
<!-- Pod to HTML conversion by the Template Toolkit version 2 -->
[% WRAPPER section
title="SYNOPSIS"
-%]<pre> # load plugin and specify XML file to parse
[% tt_start_tag %] USE xpath = XML.XPath(xmlfile) [% tt_end_tag %]
[% tt_start_tag %] USE xpath = XML.XPath(file => xmlfile) [% tt_end_tag %]
[% tt_start_tag %] USE xpath = XML.XPath(filename => xmlfile) [% tt_end_tag %]</pre>
<pre> # load plugin and specify XML text to parse
[% tt_start_tag %] USE xpath = XML.XPath(xmltext) [% tt_end_tag %]
[% tt_start_tag %] USE xpath = XML.XPath(xml => xmltext) [% tt_end_tag %]
[% tt_start_tag %] USE xpath = XML.XPath(text => xmltext) [% tt_end_tag %]</pre>
<pre> # then call any XPath methods (see XML::XPath docs)
[% tt_start_tag %] FOREACH page = xpath.findnodes('/html/body/page') [% tt_end_tag %]
[% tt_start_tag %] page.getAttribute('title') [% tt_end_tag %]
[% tt_start_tag %] END [% tt_end_tag %]</pre>
<pre> # define VIEW to present node(s)
[% tt_start_tag %] VIEW repview notfound='xmlstring' [% tt_end_tag %]
# handler block for a <report>...</report> element
[% tt_start_tag %] BLOCK report [% tt_end_tag %]
[% tt_start_tag %] item.content(view) [% tt_end_tag %]
[% tt_start_tag %] END [% tt_end_tag %]</pre>
<pre> # handler block for a <section title="...">...</section> element
[% tt_start_tag %] BLOCK section [% tt_end_tag %]
<h1>[% tt_start_tag %] item.getAttribute('title') | html [% tt_end_tag %]</h1>
[% tt_start_tag %] item.content(view) [% tt_end_tag %]
[% tt_start_tag %] END [% tt_end_tag %]</pre>
<pre> # default template block passes tags through and renders
# out the children recursivly
[% tt_start_tag %] BLOCK xmlstring;
item.starttag; item.content(view); item.endtag;
END [% tt_end_tag %]
# block to generate simple text
[% tt_start_tag %] BLOCK text; item | html; END [% tt_end_tag %]
[% tt_start_tag %] END [% tt_end_tag %]</pre>
<pre> # now present node (and children) via view
[% tt_start_tag %] repview.print(page) [% tt_end_tag %]</pre>
<pre> # or print node content via view
[% tt_start_tag %] page.content(repview) [% tt_end_tag %]</pre>
[%- END %]
[% WRAPPER section
title="PRE-REQUISITES"
-%]<p>
This plugin requires that the XML::Parser and XML::XPath modules be
installed. These are available from CPAN:
</p>
<pre> http://www.cpan.org/modules/by-module/XML</pre>
[%- END %]
[% WRAPPER section
title="DESCRIPTION"
-%]<p>
This is a Template Toolkit plugin interfacing to the XML::XPath module.
</p>
<p>
All methods implemented by the XML::XPath modules are available. In
addition, the XML::XPath::Node::Element module implements
present($view) and content($view) methods method for seamless
integration with Template Toolkit VIEWs. The XML::XPath::Node::Text
module is also adorned with a present($view) method which presents
itself via the view using the 'text' template.
</p>
<p>
To aid the reconstruction of XML, methods starttag and endtag are
added to XML::XPath::Node::Element which return the start and
end tag for that element. This means that you can easily do:
</p>
<pre> [% tt_start_tag %] item.starttag [% tt_end_tag %][% tt_start_tag %] item.content(view) [% tt_end_tag %][% tt_start_tag %] item.endtag [% tt_end_tag %]</pre>
<p>
To render out the start tag, followed by the content rendered in the
view "view", followed by the end tag.
</p>
[%- END %]
[% WRAPPER section
title="AUTHORS"
-%]<p>
This plugin module was written by Andy Wardley <abw@wardley.org>.
</p>
<p>
The XML::XPath module is by Matt Sergeant <matt@sergeant.org>.
</p>
[%- END %]
[% WRAPPER section
title="VERSION"
-%]<p>
2.70, distributed as part of the
Template Toolkit version 2.14, released on 04 October 2004.
</p>
[%- END %]
[% WRAPPER section
title="COPYRIGHT"
-%]<pre> Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved.
Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.</pre>
<p>
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
</p>
[%- END %]
[% WRAPPER section
title="SEE ALSO"
-%]<p>
[% ttlink('Template::Plugin', 'Template::Plugin') -%], [% ttlink('XML::XPath', 'XML::XPath') -%], [% ttlink('XML::Parser', 'XML::Parser') -%]
</p>
[%- END %]