<p> While this abbreviation results quite handy it requires some care when using
record patterns. As we sais the general form of a record pattern is:
</p>
<sample><![CDATA[
<(%%p1%%) (%%p2%%)>%%p3%%
]]></sample>
<p>
and the same abbreviations as for expressions apply. In particular this means
that, say, the pattern <code><t (a)>_</code> stands for <code><(`t)
(a)>_</code>. Therefore while <code><t (a)>_</code> matches all the elements of
tag <code>t</code> (and captures in the varible <code>a</code> the attributes),
the pattern <code><(t) (a)>_</code> matches all XML elements (whatever their
tag is) and captures their tag in the variable <code>t</code> (and their
attributes in <code>a</code>). Another point to notice is that <code><t>_</code>
stands for <code><t ({})>_</code> (more precisely, for <code><(`t) ({})>_</code>). Since
<code>{}</code> is the open empty record type, then it matches all the records. Therefore
<code><t>_</code> matches all elements of tag <code>t</code> whatever they have whatever they have attributes or not. In the following we enumerate some simple examples to show what we explained:
</p>
<bstyle="color:#FF0080">TO BE DONE</b>
<p>
As an example to summarize what we said above, consider the the elements
<code>table</code>, <code>td</code> and <code>tr</code> in XHTML. In
transitional XHTML these elements can have an attribute <code>bgcolor</code>
which is deprecated since in strict XHTML the background color must be specified
by the <code>style</code> attribute. So for instance <code><table
bgcolor="#ffff00" style="font-family:Arial">...</code> to conform strict XHTML
must be transformed into <code><table style="bgcolor:#ffff00;
font-family:Arial">...</code> to be XHTML strict compliant. Here is a function
that does this transformation on a very simplified version of possibly nested
tables containing strings.
</p>
<sample><![CDATA[
type Table = <table {| bgcolor=?String; style=?String |}>[ Tr+]
type Tr = <tr{|bgcolor=?String;style=?String|}>[ Td+]
type Td = <td{|bgcolor=?String;style=?String|}>[ Table* | PCDATA ]
let strict ([Table*]->[Table*]; [Tr+]->[Tr+]; [Td+]->[Td+]; [PCDATA]->[PCDATA])
x -> map x with
<(t) (a& {| bgcolor=c; style=s |})> l
-> <(t) (a \ bgcolor+{style=(s@"; bgcolor:"@c)})>(strict l)
| <(t) (a& {| bgcolor=c |})> l
-> <(t) (a \ bgcolor+{style=("bgcolor:"@c)})>(strict l)
| <(t)> l -> <(t)>(strict l)
| c -> c
]]></sample>
<p>
As an exercise the reader can try to rewrite the function strict so that the first three branches of the map are condensated into a unique branch.
<code> %%e%%/%%t%% </code> and <code> %%e%%/@%%a%% </code> where <code>%%e%%</code> is an expression, <code> %%t%% </code> a type, and <code> %%a%% </code> an attribute.
<code> %%e%%/%%t%% </code>, <code> %%e%%/@%%a%% </code>, and <code> %%e%%//%%t%% </code> where <code>%%e%%</code> is an expression, <code> %%t%% </code> a type, and <code> %%a%% </code> an attribute.