<s>
A	O
template	B-Language
processor	I-Language
(	O
also	O
known	O
as	O
a	O
template	B-Application
engine	I-Application
or	O
template	B-Protocol
parser	O
)	O
is	O
software	O
designed	O
to	O
combine	O
templates	B-Protocol
with	O
a	O
data	B-Application
model	I-Application
to	O
produce	O
result	O
documents	O
.	O
</s>
<s>
The	O
language	O
that	O
the	O
templates	B-Protocol
are	O
written	O
in	O
is	O
known	O
as	O
a	O
template	B-Language
language	I-Language
or	O
templating	B-Language
language	I-Language
.	O
</s>
<s>
A	O
template	B-Application
engine	I-Application
is	O
ordinarily	O
included	O
as	O
a	O
part	O
of	O
a	O
web	B-Application
template	I-Application
system	I-Application
or	O
application	B-Application
framework	I-Application
,	O
and	O
may	O
be	O
used	O
also	O
as	O
a	O
preprocessor	B-General_Concept
or	O
filter	B-Application
.	O
</s>
<s>
Template	B-Application
engines	I-Application
typically	O
include	O
features	O
common	O
to	O
most	O
high-level	B-Language
programming	I-Language
languages	I-Language
,	O
with	O
an	O
emphasis	O
on	O
features	O
for	O
processing	O
plain	O
text	O
.	O
</s>
<s>
While	O
template	B-Language
processors	I-Language
are	O
typically	O
a	O
separate	O
piece	O
of	O
software	O
,	O
used	O
as	O
part	O
of	O
a	O
system	O
or	O
framework	O
,	O
simple	O
templating	B-Language
languages	I-Language
are	O
commonly	O
included	O
in	O
the	O
string	O
processing	O
features	O
of	O
general-purpose	B-Language
programming	I-Language
languages	I-Language
,	O
and	O
in	O
text	O
processing	O
programs	O
,	O
notably	O
text	B-Application
editors	I-Application
or	O
word	B-General_Concept
processors	I-General_Concept
.	O
</s>
<s>
The	O
templating	B-Language
languages	I-Language
are	O
generally	O
simple	O
substitution-only	O
languages	O
,	O
in	O
contrast	O
to	O
the	O
more	O
sophisticated	O
facilities	O
in	O
full-blown	O
template	B-Language
processors	I-Language
,	O
but	O
may	O
contain	O
some	O
logic	O
.	O
</s>
<s>
Simple	O
examples	O
include	O
‘	B-Language
printf’	I-Language
print	I-Language
format	I-Language
strings	I-Language
,	O
found	O
in	O
many	O
programming	O
languages	O
,	O
and	O
snippets	B-Application
,	O
found	O
in	O
a	O
number	O
of	O
text	B-Application
editors	I-Application
and	O
source	B-Application
code	I-Application
editors	I-Application
.	O
</s>
<s>
In	O
word	B-General_Concept
processors	I-General_Concept
,	O
templates	B-Protocol
are	O
a	O
common	O
feature	O
,	O
while	O
automatic	O
filling	O
in	O
of	O
the	O
templates	B-Protocol
is	O
often	O
referred	O
to	O
as	O
mail	B-Application
merge	I-Application
.	O
</s>
<s>
An	O
illustrative	O
example	O
of	O
the	O
complementary	O
nature	O
of	O
parsing	B-Language
and	O
templating	O
is	O
the	O
s	O
(	O
substitute	O
)	O
command	O
in	O
the	O
sed	B-Application
text	O
processor	O
,	O
originating	O
from	O
search-and-replace	O
in	O
the	O
ed	B-Application
text	I-Application
editor	I-Application
.	O
</s>
<s>
Substitution	O
commands	O
are	O
of	O
the	O
form	O
s/regexp/replacement/	O
,	O
where	O
regexp	B-Language
is	O
a	O
regular	B-Language
expression	I-Language
,	O
for	O
parsing	B-Language
input	O
,	O
and	O
replacement	O
is	O
a	O
simple	O
template	B-Protocol
for	O
output	O
,	O
either	O
literal	O
text	O
,	O
or	O
a	O
format	B-Language
string	I-Language
containing	O
the	O
characters	O
&	O
for	O
"	O
entire	O
match	O
"	O
or	O
the	O
special	O
escape	O
sequences	O
\1	O
through	O
\9	O
for	O
the	O
nth	O
sub-expression	O
.	O
</s>
<s>
For	O
example	O
,	O
s/	O
( cat|dog	O
)	O
s	O
?	O
/	O
\1s/g	O
replaces	O
all	O
occurrences	O
of	O
"	O
cat	O
"	O
or	O
"	O
dog	O
"	O
with	O
"	O
cats	O
"	O
or	O
"	O
dogs	O
"	O
,	O
without	O
duplicating	O
an	O
existing	O
"	O
s	O
"	O
:	O
(	O
cat|dog	O
)	O
is	O
the	O
1st	O
(	O
and	O
only	O
)	O
sub-expression	O
in	O
the	O
regexp	B-Language
,	O
and	O
\1	O
in	O
the	O
format	B-Language
string	I-Language
substitutes	O
this	O
into	O
the	O
output	O
.	O
</s>
<s>
All	O
template	B-Protocol
processing	O
systems	O
consist	O
of	O
at	O
least	O
these	O
primary	O
elements	O
:	O
</s>
<s>
an	O
associated	O
data	B-Application
model	I-Application
;	O
</s>
<s>
one	O
or	O
more	O
source	O
templates	B-Protocol
;	O
</s>
<s>
a	O
processor	O
or	O
template	B-Application
engine	I-Application
;	O
</s>
<s>
This	O
may	O
be	O
a	O
relational	B-Application
database	I-Application
,	O
a	O
source	O
file	O
such	O
as	O
XML	B-Protocol
,	O
an	O
alternate	O
format	O
of	O
flat	B-Application
file	I-Application
database	I-Application
,	O
a	O
spreadsheet	B-Application
or	O
any	O
of	O
other	O
various	O
sources	O
of	O
preformatted	O
data	O
.	O
</s>
<s>
Some	O
template	B-Protocol
processing	O
systems	O
are	O
limited	O
in	O
the	O
types	O
of	O
data	O
that	O
can	O
be	O
used	O
.	O
</s>
<s>
Source	O
templates	B-Protocol
are	O
traditionally	O
specified	O
:	O
</s>
<s>
according	O
to	O
a	O
specially-defined	O
template	B-Language
language	I-Language
;	O
</s>
<s>
The	O
template	B-Application
engine	I-Application
is	O
responsible	O
for	O
:	O
</s>
<s>
connecting	O
to	O
the	O
data	B-Application
model	I-Application
;	O
</s>
<s>
directing	O
the	O
output	O
to	O
a	O
specific	O
pipeline	B-General_Concept
,	O
text	B-General_Concept
file	I-General_Concept
,	O
or	O
stream	B-Architecture
.	O
</s>
<s>
Additionally	O
some	O
template	B-Application
engines	I-Application
allow	O
additional	O
configuration	O
options	O
.	O
</s>
<s>
Template	B-Protocol
processing	O
is	O
used	O
in	O
various	O
contexts	O
for	O
different	O
purposes	O
.	O
</s>
<s>
The	O
specific	O
purpose	O
is	O
ordinarily	O
contingent	O
upon	O
the	O
software	B-Application
application	I-Application
or	O
template	B-Application
engine	I-Application
in	O
use	O
.	O
</s>
<s>
However	O
,	O
the	O
flexibility	O
of	O
template	B-Protocol
processing	O
systems	O
often	O
enables	O
unconventional	O
uses	O
for	O
purposes	O
not	O
originally	O
intended	O
by	O
the	O
original	O
designers	O
.	O
</s>
<s>
A	O
template	B-Application
engine	I-Application
is	O
a	O
specific	O
kind	O
of	O
template	B-Protocol
processing	O
module	O
that	O
exhibits	O
all	O
of	O
the	O
major	O
features	O
of	O
a	O
modern	O
programming	O
language	O
.	O
</s>
<s>
The	O
term	O
template	B-Application
engine	I-Application
evolved	O
as	O
a	O
generalized	O
description	O
of	O
programming	O
languages	O
whose	O
primary	O
or	O
exclusive	O
purpose	O
was	O
to	O
process	O
templates	B-Protocol
and	O
data	O
to	O
output	O
text	O
.	O
</s>
<s>
The	O
use	O
of	O
this	O
term	O
is	O
most	O
notably	O
applied	O
to	O
web	O
development	O
using	O
a	O
web	B-Application
template	I-Application
system	I-Application
,	O
and	O
it	O
is	O
also	O
applied	O
to	O
other	O
contexts	O
as	O
well	O
.	O
</s>
<s>
Document	O
generation	O
frameworks	O
typically	O
use	O
template	B-Protocol
processing	O
as	O
the	O
central	O
model	O
for	O
generating	O
documents	O
.	O
</s>
<s>
Source	O
code	O
generation	O
tools	O
support	O
generation	O
of	O
source	O
code	O
(	O
as	O
the	O
result	O
documents	O
)	O
from	O
abstract	O
data	B-Application
models	I-Application
(	O
e.g.	O
,	O
UML	O
,	O
relational	O
data	O
,	O
domain-specific	O
enterprise	O
data	O
stores	O
)	O
for	O
particular	O
application	O
domains	O
,	O
particular	O
organizations	O
,	O
or	O
in	O
simplifying	O
the	O
production	O
process	O
for	O
computer	B-Application
programmers	I-Application
.	O
</s>
<s>
A	O
web	B-Application
template	I-Application
engine	I-Application
processes	O
web	B-Application
templates	I-Application
and	O
source	O
data	O
(	O
typically	O
from	O
a	O
relational	B-Application
database	I-Application
)	O
to	O
produce	O
one	O
or	O
more	O
output	O
web	O
pages	O
or	O
page	O
fragments	O
.	O
</s>
<s>
It	O
is	O
ordinarily	O
included	O
as	O
a	O
part	O
of	O
a	O
web	B-Application
template	I-Application
system	I-Application
or	O
application	B-Application
framework	I-Application
.	O
</s>
<s>
Currently	O
,	O
template	B-Protocol
processing	O
software	O
is	O
most	O
frequently	O
used	O
in	O
the	O
context	O
of	O
development	O
for	O
the	O
web	O
.	O
</s>
<s>
XSLT	B-Application
is	O
a	O
template	B-Protocol
processing	O
model	O
designed	O
by	O
W3C	O
.	O
</s>
<s>
It	O
is	O
designed	O
primarily	O
for	O
transformations	O
on	O
XML	B-Protocol
data	O
(	O
into	O
web	O
documents	O
or	O
other	O
output	O
)	O
.	O
</s>
<s>
Programming	O
languages	O
such	O
as	O
Perl	B-Language
,	O
Python	B-Language
,	O
PHP	B-Application
,	O
Ruby	B-Language
,	O
C#	B-Application
,	O
Java	B-Language
,	O
and	O
Go	O
support	O
template	B-Protocol
processing	O
either	O
natively	O
,	O
or	O
through	O
add-on	O
libraries	O
and	O
modules	O
.	O
</s>
<s>
JavaServer	B-Language
Pages	I-Language
,	O
Active	B-General_Concept
Server	I-General_Concept
Pages	I-General_Concept
,	O
Genshi	B-Language
(	O
for	O
Python	B-Language
)	O
,	O
and	O
eRuby	B-Application
are	O
examples	O
of	O
template	B-Application
engines	I-Application
designed	O
specifically	O
for	O
web	O
application	O
development	O
.	O
</s>
<s>
Moreover	O
,	O
template	B-Protocol
processing	O
is	O
sometimes	O
included	O
as	O
a	O
sub-feature	O
of	O
software	O
packages	O
like	O
text	B-Application
editors	I-Application
,	O
IDEs	O
and	O
relational	B-Application
database	I-Application
management	I-Application
systems	I-Application
.	O
</s>
