> Here is an (actual) example of the problem: > > <table width="100%"> > <my:pgloop sth=$sth> > <fmt>PRICE:%.2f</fmt> > <tr> > <td><my:pimage pg="__PG__" sku="__SKU__" width="32"/></td> > <td><a href="catalog/__PG__/__SKU__">__SKU__</a></td> > <td>__USER1__</td> > <td>__NAME__</td> > <td align=right>__QTY_ONHAND__</td> > <td align=right>__AMT_PRICE__</td> > </tr> > </my:pgloop> > </table>
Ta-Da! Here is the nifty solution... By slightly changing the template-- notice the 'my:pimage' xmlsub now has a different format using __[ ... ]__ to distinguish it instead (and the syntax is consistent with the __TOKEN__ style). This keeps it from getting processed before it gets passed to the first xmlsub (my:pgloop). Then, in the render() func, add one more statement to change the __[ ]__ nomenclature back to < > and then pass it through $Response->Include() instead of printing it directly. This has the effect of substituting the parameters, fixing up the embedded xmlsubs, and then re-processing everything with the now-current data. By using $Response->Include to do it, the now correct xmlsubs will get processed with the substituted data. <table width="100%"> <my:pgloop sth=$sth> <fmt>PRICE:%.2f</fmt> <tr> <td>__[my:pimage pg="__PG__" sku="__SKU__" width="32"/]__</td> <td><a href="catalog/__PG__/__SKU__"><u>__SKU__</u></a></td> <td>__USER1__</td> <td>__NAME__</td> <td align=right>__QTY_ONHAND__</td> <td align=right>__AMT_PRICE__</td> </tr> </my:pgloop> </table> The completed render() function looks like this: sub render { ## process a body-template string and render appropriately my ($tmpl, $hash, $fmt) = @_; $tmpl =~ s/__\[(.*?)\]__/<$1>/gm; # fixup delayed-embedded xmlsubs while ($tmpl =~ /__(.*?)__/) { my $TOKEN = $1; my $token = lc($TOKEN); if ((my $fmt = $$fmt{$TOKEN}) ne undef) { # to-uppercase if ($fmt =~ /^%uc/i) { $fmt =~ s/[^0-9]//gm; $$hash{$token} = uc(substr($$hash{$token}, 0, $fmt || length($$hash{$token}))); } # to-lowercase elsif ($fmt =~ /^%lc/i) { $fmt =~ s/[^0-9]//gm; $$hash{$token} = lc(substr($$hash{$token}, 0, $fmt || length($$hash{$token}))); } # picture else { $$hash{$token} = sprintf($fmt, $$hash{$token}); } } $tmpl =~ s/__${TOKEN}__/$$hash{$token}/gme; } $Response->Include(\$tmpl); } __END__ -------------------------------------------------------------------------------- Check out http://www.Wizard.Org for great deals on Electronic Parts *NEW* Computer Parts & Accessories - Drives - LCD - Systems - Linux -------------------------------------------------------------------------------- ** Affordable Online Store w/Merchant Card Processing & Paypal ** Write to us: [EMAIL PROTECTED] -- Get your Store Online Today! -------------------------------------------------------------------------------- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]