# Diff of /web/examples/xtransform.cd

revision 549 by abate, Tue Jul 10 17:43:30 2007 UTC revision 550 by abate, Tue Jul 10 17:43:38 2007 UTC
# Line 3  Line 3
3     simplified definition of Xhtml     simplified definition of Xhtml
4  *)  *)
5

6  type Flow = Char | Block | Inline  ;;  type Flow = Char | Block | Inline  ;;
7  type Block = P | Heading | Lists | Blocktext | Char  type Block = P | Heading | Lists | Blocktext | Char
8  type Lists = Ul  type Lists = Ul
# Line 34  Line 32
32  type Big = <big>[ Inline* ];;  type Big = <big>[ Inline* ];;
33  type Small = <small>[ Inline* ];;  type Small = <small>[ Inline* ];;
34
35
36  (* xtransform matches the patterns against the root element of each  (* xtransform matches the patterns against the root element of each
37     XML tree and, if it fails, it recursively applies itself to the     XML tree and, if it fails, it recursively applies itself to the
38     sequence of sons of the root.     sequence of sons of the root.
# Line 42  Line 41
41     document as follows     document as follows
42  *)  *)
43

44  let bold(x:[Xhtml]):[Xhtml]=xtransform x with <a (y)>t -> [ <a(y)>[<b>t] ]  let bold(x:[Xhtml]):[Xhtml]=xtransform x with <a (y)>t -> [ <a(y)>[<b>t] ]
45
46
47  (* let us apply the function to a document where links appear  (* let us apply the function to a document where links appear
48     at different depths     at different depths
49  *)  *)
# Line 57  Line 54
55      <body>[      <body>[
56        <h2>['You can have links ' <a href="here">"here"]        <h2>['You can have links ' <a href="here">"here"]
57        <p>['Or they can be down']        <pre>['Or they can be down']
58        <ul>[        <ul>[
59          <li>['In ' <a name="list">"lists" ' for instance']          <li>['In ' <a name="list">"lists" ' for instance']
60          <li>['or you oddly decided to '          <li>['or you oddly decided to '
# Line 68  Line 65
66          'and even if they are in fancy ' <a name="address">"address boxes"          'and even if they are in fancy ' <a name="address">"address boxes"
67       ]       ]
68       <p>['nevertheless ' <a href="http://www.cduce.org">"Cduce" ' and '        <p>[
69           <a href="xtransform">[<tt>"xtransform"] ' will put all links in bold ']            'nevertheless ' <a href="http://www.cduce.org">"Cduce" ' and '
70              <a href="xtransform">[<tt>"xtransform"]
71              ' will put all links in bold so that when'
72              ' you program your transformation you '
73              <big>[<a name="">" don\'t " ] ' have to worry about it'
74         ]
75      ]      ]
76    ];;    ];;
77
78  bold [doc];;  bold [doc];;
79
80  match  let [x] = bold [doc] in print_xml x;;

Legend:
 Removed from v.549 changed lines Added in v.550