<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<!-- edited with XMLSPY v2004 rel. 3 U (http://www.xmlspy.com) by Andy Robinson (ReportLab Europe Ltd.) -->
<!DOCTYPE document SYSTEM "../dynamic_rml.dtd">
<document filename="test_020_dynamic.pdf">
	<!-- this needs to be driven by the preprocessor...-->
	<acquire>
		<xmlData name="data" fileName="test_020_sampledata.xml"/>
	</acquire>
	<template pageSize="(595, 842)" leftMargin="72" showBoundary="0">
		<pageTemplate id="main" pageSize="(595,842)">
			<pageGraphics>
				<setFont name="Helvetica-BoldOblique" size="18"/>
				<drawRightString x="523" y="780">RML2PDF Test Suite - Dynamic RML</drawRightString>
				<setFont name="Helvetica" size="10"/>
				<drawCenteredString x="297" y="25">Page <pageNumber/>
				</drawCenteredString>
			</pageGraphics>
			<frame id="first" x1="1in" y1="1in" width="6.27in" height="9.69in"/>
		</pageTemplate>
	</template>
	<stylesheet>
		<initialize>
			<alias id="style.normal" value="style.Normal"/>
		</initialize>
		<paraStyle name="h1" fontName="Helvetica-Bold" fontSize="12" spaceBefore="12" leading="15"/>
		<paraStyle name="normal" fontName="Helvetica" fontSize="10" spaceBefore="6" leading="12"/>
		<paraStyle name="code" fontName="Courier" fontSize="8" leading="10" textColor="navy" leftIndent="36" rightIndent="36"/>
	</stylesheet>
	<story>
		<assign_b name="author" value="Andy Robinson"/>
		<para style="h1">Dynamic RML</para>
		<para style="normal">This adds dynamic capabilities.  Say that again a few times with a LOOP tag..</para>
		<spacer length="8"/>
		<loop_b var="i" in="range(5)">
			<para style="code">pass <expr>i</expr>: this adds dynamic capabilities</para>
		</loop_b>
		<para style="normal">The author's name was assigned earlier, and it is:  <expr>author</expr>.  Here is the system path:</para>
		<script_b>import sys</script_b>
		<spacer length="8"/>
		<loop_b var="dirName" in="sys.path">
			<pre style="code">
				<expr>dirName</expr>
			</pre>
		</loop_b>
		<para style="h1">Data acquisition</para>
		<para style="normal">This document uses a data tag to slurp in a source XML document in  "sample_invoice.xml".  The source is here...(in fact, this could
    be useful once I have the escaping sorted out....)</para>
<xpre style="code">
<expr escape="off" encoding="iso-8859-1">open('test_020_sampledata.xml').read()</expr>
</xpre>
		<para style="normal">This can be referred to with the dynamic tags.  Let's pull out the customer name from a node in the file: <b>
				<expr>data.invoice.customerDetails.customerName</expr>
			</b>.  Now let's do a loop over some elements...</para>
		<spacer length="8"/>
		<blockTable colWidths="100,50,50,50">
			<blockTableStyle id="grid">
				<lineStyle kind="GRID" colorName="black"/>
			</blockTableStyle>
			<tr>
				<td>Description</td>
				<td>Unit Price</td>
				<td>Qty</td>
				<td>Line Price</td>
			</tr>
			<loop_t var="line" in="data.invoice.lines">
				<tr>
					<td>
						<expr>line</expr>
					</td>
					<td>
						<expr>line.unitPrice</expr>
					</td>
					<td>
						<expr>line.qty</expr>
					</td>
					<td>etc</td>
				</tr>
			</loop_t>
		</blockTable>

		<nextPage/>
		<para style="h1">Doclets</para>
		<para>This is a test of doclets.  Doclets are a new part of the framework in 2005 and aim to allow creation
		of smart "reusable objects" which know how to render themselves at a lower level.</para>

		<para>Doclets know how to pull data from a data model, and draw themselves in response.</para>
		
		<para>A simple doclet is provided in the class rlextra.rml2pdf.doclet.TestReverseDoclet.  This draws a little table with a string (which is the data passed in) and the same string reversed.  We can pass it a single (quoted) string in an attribute:</para>

		<doclet module="rlextra.rml2pdf.doclet" class="TestReverseDoclet" data="'Cowabunga!'"/>
		
		<para>The key thing is that the data parameter is a variable name in the dynamic RML namespace.  If absent, the doclet sees
		the whole namespace.  So we can use doclets inside loops and conditionals and pass through actual variables
		to them - not just flattened-out strings. This example shows dynamic use; it should generate reverse doclets for each 
		inner planet name:	</para>
		
		<loop_b var="planet" in="'Mercury Venus Earth Mars'.split()">
			<doclet module="rlextra.rml2pdf.doclet" class="TestReverseDoclet" data="planet"/>
			<spacer length="6"/>
		</loop_b>

		<para>"Yeah, right, big deal", I hear you say.  But consider that the doclet might know how to connect to
		a customer database in a fund manager and plot a table and chart of the investor's holdings, given just
		a customer ID and an open database connectionas parameters.:	</para>
		

	</story>
</document>
