Apache-ASP

 view release on metacpan or  search on metacpan

site/xml.html  view on Meta::CPAN

</center>

</td>



<td valign=top bgcolor=white>
<font size=+0 face=verdana,arial>

<font face=verdana><font class=title size=+1 color=#555555><b>XML/XSLT</b></font>
</font>

	<hr size=1>
	<table width=100% border=0 cellpadding=1 cellspacing=3>
	<tr>
	<td valign=top><font face="lucida console" size=-1>
	
		<tr>
		
			<td valign=top >
			<font face="lucida console" size=-1>
			<a href=#Custom%20Tags%20343d11d8>Custom Tags with XMLSubsMatch</a>
			</font>
			</td>
		
			<td valign=top >
			<font face="lucida console" size=-1>
			<a href=#References>References</a>
			</font>
			</td>
							
		</tr>
		
		<tr>
		
			<td valign=top >
			<font face="lucida console" size=-1>
			<a href=#XSLT%20Tranfor41f72a4d>XSLT Tranformations</a>
			</font>
			</td>
		<td>&nbsp;</td>					
		</tr>
			
	</table>
	<hr size=1>
	<p>

	<p>
	<a name=Custom%20Tags%20343d11d8></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Custom Tags with XMLSubsMatch</b></font>
<font face="courier new" size=3><pre>
</pre></font>Before XML, there was the need to make HTML markup smarter.
Apache::ASP gives you the ability to have a perl
subroutine handle the execution of any predefined tag,
taking the tag descriptors, and the text contained between,
as arguments of the subroutine.  This custom tag
technology can be used to extend a web developer&#39;s abilities
to add dynamic pieces without having to visibly use 
&lt;% %&gt; style code entries.
<font face="courier new" size=3><pre>
</pre></font>So, lets say that you have a table that 
you want to insert for an employee with contact 
info and the like, you could set up a tag like:
<font face="courier new" size=3><pre>
 &lt;my:new-employee name=&quot;Jane&quot; last=&quot;Doe&quot; phone=&quot;555-2222&quot;&gt;
   Jane Doe has been here since 1998.
 &lt;/my:new-employee&gt;
</pre></font>To render it with a custom tag, you would tell 
the Apache::ASP parser to render the tag with a 
subroutine:
<font face="courier new" size=3><pre>
  PerlSetVar XMLSubsMatch my:new-employee
</pre></font>Any colons, &#39;:&#39;, in the XML custom tag will turn
into &#39;::&#39;, a perl package separator, so the my:employee
tag would translate to the my::employee subroutine, or the 
employee subroutine in the my package.  Any dash &quot;-&quot; will 
also be translated to an underscore &quot;_&quot;, as dash is not valid
in the names of perl subroutines.
<font face="courier new" size=3><pre>
</pre></font>Then you would create the my::employee subroutine in the my 
perl package or whereever like so:
<font face="courier new" size=3><pre>
  package my;
  sub new_employee {
    my($attributes, $body) = @_;
    $main::Response-&gt;Include(&#39;new_employee.inc&#39;, $attributes, $body);
  }
  1;

  &lt;!-- # new_employee.inc file somewhere else, maybe in Global directory --&gt;
  &lt;% my($attributes, $body) = @_; %&gt;
  <table>
  &lt;% for('name', 'last', 'phone') { %&gt;
    <tr>
      <td><b>&lt;%=ucfirst $_ %&gt;</b>:</td>
      <td>&lt;%= $attributes->{$_} %&gt;</td>
    </tr>
  &lt;% } %&gt;
  <tr><td colspan=2>&lt;%= $body %&gt;</td></tr>
  </table>
  &lt;!-- # end new_employee.inc file --&gt;
</pre></font>The $main::Response-&gt;Include() would then delegate the rendering
of the new-employee to the new_employee.inc ASP script include.
<font face="courier new" size=3><pre>
</pre></font>Though XML purists would not like this custom tag technology
to be related to XML, the reality is that a careful
site engineer could render full XML documents with this
technology, applying all the correct styles that one might
otherwise do with XSLT. 
<font face="courier new" size=3><pre>
</pre></font>Custom tags defined in this way can be used as XML tags
are defined with both a body and without as it
<font face="courier new" size=3><pre>
  &lt;my:new-employee&gt;...&lt;/my:new-employee&gt;
</pre></font>and just
<font face="courier new" size=3><pre>
  &lt;my:new-employee /&gt;
</pre></font>These tags are very powerful in that they can also
enclose normal ASP logic, like:
<font face="courier new" size=3><pre>
  &lt;my:new-employee&gt;



( run in 0.415 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )