[Petal] XIncludes problem and question
William McKee
william at knowmad.com
Thu Feb 13 22:26:27 GMT 2003
Hi everyone,
Time for more XInclude fun. First, a simple question. If I use an
xi:include tag in the head of an html document do I need to move the
xmlns definition into the <head> tag? Currently I'm putting it in the
<body> tag. Maybe I should move it into the <html> tag? The more I learn
about XML, the more confused I get.
As for the problem, I have attached three files to demonstrate the
problem I am getting. Basically, the '<' is being rewritten to < but
the '>' is not. The header.tmpl file is expected to be in an includes/
directory.
Thanks,
William
--
Knowmad Services Inc.
http://www.knowmad.com
-------------- next part --------------
<!--?
# Template: test.tmpl
# Created: 07-23-2002
# Modified: 02-13-2003
# Author: wlm
# Description: Template to do terrible things to test Petal template language.
-->
<html>
<head>
<title>Petal Stress Test Template</title>
</head>
<body xmlns:xi="http://www.w3.org/2001/XInclude">
<h3>Current Petal version: <span petal:replace="petal/version"</h3>
<h3>The tags:</h3>
<ul>
<li>error_message: <span petal:content="error_message">Error</span></li>
<li>first_name: <span petal:content="first_name">First</span></li>
<li>last_name: <span petal:content="last_name">Last</span></li>
<li>boolean: <span petal:content="boolean">boolean</span></li>
<li>alltests: <span petal:content="alltests">alltests</span></li>
<li>pg_boolean: <span petal:content="pg_boolean">pg_boolean</span></li>
<li>pg_boolean_false: <span petal:content="pg_boolean_false">pg_boolean_false</span></li>
<li>email: <span petal:content="email">Email</span></li>
<li>
Students List<br />
<ul><li style="font-weight: bold"> Name - Email</li></ul>
<ul petal:repeat="student students">
<li><span petal:replace="student.first_name">first</span>
<span petal:replace="student.last_name">last</span>
- <span petal:replace="student.email">email</span>
</li>
</ul>
</li>
</ul>
<hr size="9" width="95%" />
<table bgcolor="yellow">
<tr>
<td>
<h3>The Non-Working Tests</h3>
</td>
</tr>
</table>
<h4>XIncludes problem</h4>
<p>This example includes an external file with a JavaScript snippet that causes < to be output as &lt;. It does not affect the > which is odd. Look at source.</p>
<xi:include href="./includes/header.tmpl">
<h4>KNOWN ERROR - Rewrite error</h4>
<p>This example shows how Petal is changing some HTML attributes when creating its output. In this example, values are changed to real spaces which is not the desired result when creating XHTML output. I built this as a table to try to repeat a problem I saw where adding &nbsp; attributes was causing Petal to add an extra row. It's probably a problem with my other template.</p>
<table border="1">
<tr>
<td>Column 1</td>
<td>Column 2</td>
</tr>
<tr>
<td colspan="2"><input type="button" value="Button 1"> <input type="button" value="Button 2"></td>
</tr>
</table>
<!--? The following tests are working. Set RUNALLTESTS to 1 to run these -->
<div petal:condition="true:alltests"?>
<p> </p>
<hr size="9" width="95%">
<p> </p>
<table bgcolor="yellow"><tr><td> <h3>The Working Tests</h3></td></tr></table>
<h4>Includes with loops</h4>
<p>Included templates that contain loops.</p>
<?petal:include file="includes/loops.tmpl"?>
<p> </p>
<hr size="9" width="95%">
<h4>Structure modifier error</h4>
<p>THIS WAS A TEMPLATE ERROR (due to using wrong syntax). This example shows how Petal is not outputting variables that use the structure modifier. The first paragraph outputs the value directory whereas the second uses the structure modifier.</p>
<ol>
<li><p petal:replace="html_string"></p></li>
<li><p petal:replace="structure html_string"></p></li>
</ol>
<p> </p>
<hr size="9" width="95%">
<h3>The Working Tests</h3>
<h4>Canonical tag error in XHTML parser</h4>
<p>Errors occur when trying to use the canonical format in templates parsed by the XHTML parser.</p>
<?petal:repeat name="student students"?>
<ul>
<li><?petal:var name="student.first_name"?>
<?petal:var name="student.last_name"?>
- <?petal:var name="student.email"?>
</li>
</ul>
<?petal:end?>
<h4>Parameter rewrite errors</h4>
<p>THIS IS STANDARD XHTML and thus not a bug</p>
<p>Petal rewrites parameters without regard to case. This is a problem for some Javascript scripts.</p>
<form><input type="string" PARM="PHN" wCLASS="FormatText" size="30" maxlength="55"></form>
<br>
<a href="" onMouseOver="alert('Hi mom')">Mouse Over Test</a>
<h4>HTML Comments error</h4>
<p>This example illustrates how HTML comments get removed when using the XHTML/XHTML input/output settings in Petal.</p>
<!-- This is a test. It will disappear. -->
<h4>Postgres true/false</h4>
<p>Test the new handlers I wrote.</p>
<ul>
<li>True = <span petal:content="pg_true: pg_boolean">t</span></li>
<li>False = <span petal:content="pg_false: pg_boolean_false">t</span></li>
</ul>
<h4>String modifier error II</h4>
<p>This example illustrates how the __count__ value is not being properly handled in string statements. It also shows how the name attribute is not being properly built in an input element as well.</p>
<ul petal:repeat="student students">
<li><?petal:var name="string:$__count__ - $student.first_name"?>
<?petal:var name="student.last_name"?>
- <?petal:var name="student.email"?> -
<input petal:attr="name string:first_name${__count__}; value student.first_name" type="string" />
</li>
</ul>
<h4>String modifier error</h4>
<p><a petal:attr="href string:test.cgi?rm=edit_coach&fn=$first_name"><?petal:var name="first_name"?>
<?petal:var name="last_name"?>
</a></p>
<p><a petal:attr="href string:mailto://$email"><span petal:content="email">Email</span></a></p>
<p>Stacked petal tags</p>
<p class="error" petal:if="error_message" petal:content="error_message">Error</p>
<hr size="5" width="75%">
<p>1. A tag within an html tag property doesn't work, in some cases. Works if there is no include tag above it. Does not work if there is an include tag above it.
<br />
<a href="mailto:<?petal:var name="email"?>">Email</a>
</p>
<hr size="5" width="75%">
<p>2. Two tags in a row will only show the first, or nothing at all. I'm not sure why this format isn't working at all in this test template. It does work in another of my templates. Perhaps it is due to the error in the above tag. Commenting out the above tag doesn't seem to make any difference, though. Do tags inside of comments get executed?
<br />
<?petal:var name="first_name"?> <br />
<?petal:var name="first_name"?> <?petal:var name="last_name"?>
</p>
<hr size="5" width="75%">
<p>3. Includes don't always work. Try moving one of the tags to the top and see the results. Rather curious... If you move the footer to the top, you'll see that it gets shown twice if you have 2 footer includes statements following it; if you remove the last one just above the /body tag, you'll see the one after header isn't working, but further ones do. There is apparently something in the header.tmpl document which is causing Petal to not perform the next includes. In fact, you can keep adding footer includes and get more and more results as expected.
<br />
<?petal:include file="includes/header.tmpl"?>
<p>This include won't get displayed</p>
<?petal:include file="includes/footer.tmpl"?>
<hr size="5" width="75%">
<p>Creating a link</p>
<ul petal:repeat="student students">
<li><a href=""><?petal:var name="student.first_name"?> <?petal:var name="student.last_name"?> - <?petal:var name="student.email"?></a></li>
</ul>
<hr size="5" width="75%">
</div>
<!--?
<h3>End Tests</h3>
<?petal:include file="includes/footer.tmpl" taint="1"?>
-->
</body>
</html>
-------------- next part --------------
#!/usr/bin/perl
#
use strict;
use Petal;
use CGI::Carp qw/fatalsToBrowser/;
use IO::File;
use constant RUNALLTESTS => 0;
# Extend the list of modifiers
use lib qw ( ./ );
$Petal::Hash::MODIFIERS->{pg_true} = 'Postgres::TRUE';
$Petal::Hash::MODIFIERS->{pg_false} = 'Postgres::FALSE';
$ENV{PATH} = "/bin:/usr/bin";
my $template_file = 'test.tmpl';
$Petal::DISK_CACHE = 0;
$Petal::MEMORY_CACHE = 0;
$Petal::TAINT = 1;
$Petal::BASE_DIR = './';
$Petal::INPUT = "XHTML";
#$Petal::INPUT = "XML";
$Petal::OUTPUT = "XHTML";
#$Petal::OUTPUT = "XML";
my $template = new Petal ($template_file);
my $hash = {
petal => { version => $Petal::VERSION },
alltests => RUNALLTESTS,
error_message => "Kilroy was Here",
first_name => "William",
last_name => "McKee",
email => 'william at knowmad.com',
boolean => '1',
pg_boolean => 't',
pg_boolean_false => 'f',
students => [ { student_id => '1',
first_name => 'William',
last_name => 'McKee',
email => 'william at knowmad.com',
},
{ student_id => '2',
first_name => 'Elizabeth',
last_name => 'McKee',
email => 'elizabeth at knowmad.com',
},
],
html_string => '<h1 align="center">Header1 Centered</h1>',
};
my $html = $template->process($hash);
print "Content-type: text/html\n\n";
print $html;
-------------- next part --------------
<form>
<table>
<tr>
<td>Field 1 (this is wrong):</td>
<td>
<script language="JavaScript">
document.write('<input type="text" name="test" size="15">');
</script>
</td>
</tr>
<tr>
<td>Field 2 (this is right):</td>
<td> <input type="text" name="test2" size="15"></td>
</tr>
</table>
</form>
More information about the Petal
mailing list