NAME
XML::XPathTemplate - Easy access to XML files using XPath and HTML::Template
SYNOPSIS
In your perl code:
my $xpt = new XML::XPathTemplate(default_lang => 'en',
root_dir = $root_dir);
my $output = $xpt->process(xpt_filename => $xpt_filename,
xml_filename => $xml_filename,
lang => 'en');
# hash references containing filenames and mtimes, used by PageKit for
# caching
my $file_mtimes = $xpt->file_mtimes;
Your XPathTemplate template:
Header
<CONTENT_VAR NAME="document('foo.xml')/aaa/bbb">
<CONTENT_VAR NAME="/ddd/aaa/@bbb">
<CONTENT_VAR NAME="/ddd/eee">
<CONTENT_VAR NAME="eee">
<CONTENT_LOOP NAME="/ddd/fff">
<CONTENT_VAR NAME="@ttt">
<CONTENT_VAR NAME="ggg">
<CONTENT_VAR NAME="hhh"> <CONTENT_VAR NAME="hhh/@qqq">
<CONTENT_VAR NAME="iii">
</CONTENT_LOOP>
Footer
Your XML file:
<ddd>
<aaa bbb="ccc"/>
<eee>jjj</eee>
<fff ttt="uuu">
<ggg>sss</ggg>
<hhh qqq="rrr">lll</hhh>
<iii>mmm</iii>
</fff>
<fff ttt="vvv">
<ggg>nnn</ggg>
<hhh>ooo</hhh>
<iii>ppp</iii>
</fff>
</ddd>
Second XML file (foo.xml)
<aaa>
<bbb>Content from second XML file</bbb>
</aaa>
Output:
Header
Content from second XML file
ccc
jjj
jjj
uuu
sss
lll rrr
mmm
vvv
nnn
ooo
ppp
Footer
DESCRIPTION
This is an easy to use templating system for extracting content from XML files. It is based on <HTML::Template>'s <TMPL_VAR> and <TMPL_LOOP> tags and uses XML::XPath to extract the requested XML content.
It has built-in support for language localization.
METHODS
- process_all_lang
-
Processes the template and returns a hash reference containing language codes as keys and outputs as values.
my $lang_output = $xpt->process_all_lang(filename => $filename); # english output my $output_en = $lang_output->{'en'};
AUTHOR
T.J. Mather (tjmather@anidea.com)
BUGS
If you use the same XPath query for a CONTENT_LOOP as well as a CONTENT_VAR tag, then HTML::Template will croak. A workaround is to append a "/." at the end of the xpath query.
COPYRIGHT
Copyright (c) 2000, 2001 AnIdea Corporation. All rights Reserved. PageKit is a trademark of AnIdea Corporation.
LICENSE
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Ricoh Source Code Public License for more details.
You can redistribute this module and/or modify it only under the terms of the Ricoh Source Code Public License.
You should have received a copy of the Ricoh Source Code Public License along with this program; if not, obtain one at http://www.pagekit.org/license