*       VT.ref    14.04.2001
*  Interpretation of XSLT
*  Trancformation + Validation + local Filtr

*$MST_FROM_ENTRY;
*$CALL_DEPTH 0;
*$DEPTH 0;
*$LENGTH 0;

$ENTRY VT {
  ((s.tag) e.xml) = <Int (<Template_ s.tag>) ((s.tag) e.xml)>;
 }

Apply {
   = ;
  s.text e.xml = s.text <Apply e.xml>;
  ((s.tag e.attr) e.xml1) e.xml2 = 
         <Int (<Template_  s.tag>) ((s.tag e.attr) e.xml1)>
         <Apply e.xml2>;
 }

Int {
  ( ) (e.xml) = ;

  ( s.text e.xslt) (e.xml) = s.text 
                  <Int (e.xslt) (e.xml)>;

  ( ((s.tag e.attr) e.xslt1) e.xslt2) (e.xml) =
                  ((s.tag e.attr) <Int (e.xslt1) (e.xml)> )
                                  <Int (e.xslt2) (e.xml)>;

  ( (((xsl s.op) e.xslt) e.2) e.3) (e.xml) =
                  <IntXsl (((xsl s.op) e.xslt) e.2) (e.xml)>
                  <Int (e.3) (e.xml)>;
 }
* --------------------------------------------------------
* One rule of transformation 
* --------------------------------------------------------

IntXsl {
   ( ((xsl apply-templates)) ) ((s.tag e.attr) e.xml) =
                 <Apply <DelTop <IntDTD ((s.tag e.attr) e.xml)>>>;

   ( ((xsl apply-templates) (select e.path)) e.2) (e.xml) =
                 <Apply <Select (e.path) (e.xml)>>;

   ( ((xsl call-template) (name (e.name)))) (e.xml) = 
                 <Int (<Template_ e.name> ) (e.xml)>;

   ( ((xsl call-template) (name (s.name))) 
   ( ((xsl with-param) (name (s.name1))) e.xslt) ) (e.xml) =
                <Template (s.name) (s.name1) (e.xslt) (e.xml)>;

   ( ((xsl choose)) e.xslt) (e.xml) = <Choose (e.xslt) (e.xml)>;

   ( ((xsl copy-of) (select e.path)) ) (e.xml) =
                 <SelectZ (e.path) (e.xml)>; 

   ( ((xsl element)   (name (e.name1 )) )
   ( ((xsl attribute) (name (e.name2 )) ) e.xslt1) e.xslt2) (e.xml) =
        ((e.name1 (e.name2 <Int (e.xslt1) (e.xml)> ))
                           <Int (e.xslt2) (e.xml)>);

   ( ((xsl for-each) (select e.path)) e.xslt) (e.xml) = 
            <For_each (e.xslt) <Select (e.path) (e.xml)>>;

   ( ((xsl if) (test (e.cond) (e.arg1) (e.arg2))) e.xslt) (e.xml) = 
        <If1 <If (e.cond) (<Value <SelectZ (e.arg1) (e.xml)>>) 
                          (<Value <SelectZ (e.arg2) (e.xml)>>)
                                  (e.xslt) (e.xml)>>;

   ( ((xsl param) e.attr) e.1) (e.xml) = ;

   ( ((xsl text) ) s.text) (e.xml) = s.text;

   ( ((xsl value-of) (select e.path)) ) (e.xml) =
                     <Value <SelectZ (e.path) (e.xml)>>; 
  }
* =================================================
Value {
 s.text e.xml = s.text;
  = ;
 ((e.tag) s.text) e.xml  = s.text ;
 }

Eq {
  (s.a) (s.a) = T;
  (   ) (   ) = T;
  (e.a) (e.b) = F;
 }

DelTop {
   ((s.tag e.attr) e.xml) = e.xml;
 }
* =================================================
Choose {
(( ((xsl when) (test (e.1) (e.2) (e.3))) e.xslt1) e.xslt2)(e.xml) =
   <Choose1 <If (e.1) (<Value <SelectZ (e.2) (e.xml)>>) 
                  (<Value <SelectZ (e.3) (e.xml)>>)
                        (e.xslt1) (e.xslt2) (e.xml)>>;
(( ((xsl otherwise)) e.xslt)) (e.xml) =
               <Int (e.xslt) (e.xml)>;
( ) (e.xml) = ;
 }

Choose1 {
    T  (e.xslt1) (e.xslt2) (e.xml) =
                <Int (e.xslt1) (e.xml)>;
    F  (e.xslt1) (e.xslt2) (e.xml) = 
                 <Choose (e.xslt2) (e.xml)>;
 }
* ===================================================
If {
  ('!=') (e.1) (e.2) e.34 =   <Not <Eq (e.1) (e.2)>> e.34;
  ( '=') (e.1) (e.2) e.34 =        <Eq (e.1) (e.2)>  e.34;
 }

If1 {
    T  (e.xslt) (e.xml) = <Int (e.xslt) (e.xml)>;
    F  (e.xslt) (e.xml) = ;
 }

Not {
        T = F;
        F = T;
 }
* ==================================================
For_each {
  (e.xslt) = ;
  (e.xslt) (e.xml1) e.xml2 = <Int (e.xslt) (e.xml1)>
                             <For_each (e.xslt) e.xml2>;
 }
* ===================================================
Template {
   (s.name) (s.name1) (e.xslt) (e.xml) =
    <Int ( <Template_ s.name  (<Int (e.xslt) (e.xml)>)> ) (e.xml)>;
 }
* ===================================================
Select {
   (('$' s.name (e.1)) e.path) (e.xml) = 
                          <Select1_node  (e.path) e.1>;

   (("xt:node-set" ('$' s.name (e.1))) e.path) (e.xml) = 
                          <Select1_node  (e.path) e.1>;

   (('.')) (e.xml) = (e.xml);
   ((text  s.text )) (e.xml) = s.text;
   (e.path) (e.xml) = <Select2 (e.path) (e.xml)>;
 }

Select1_node {
  (  ) e.1 = e.1;
  ((s.name) e.path) e.1 = <Select1 (e.path) <SelectA_node (s.name)
                          <IntDTD e.1>>>;
 }

Select1 { 
  (e.path) = ;
  (e.path) (e.xml1) e.xml2 = <Select2 (e.path) (e.xml1)>
                             <Select1 (e.path) e.xml2>;
 }

Select2 {
  ( ) e.xml = e.xml;
  ((e.1)) (e.xml) = <SelectA (e.1) <IntDTD (e.xml)>>; 
  ((e.1) e.3) (e.xml) = <Select1 (e.3)
                        <SelectA (e.1) <IntDTD (e.xml)>>>;
 }

SelectA {
   ('@' s.name) ((s.tag e.attr) e.xml) = <GetAttr s.name e.attr>;
   (s.name) ((e.tag)) = ;
   (s.name) ((e.tag) ((s.name e.attr) e.xml1) e.xml2) =
                     ((s.name e.attr) e.xml1)
                     <SelectA (s.name) ((e.tag) e.xml2)>;
   (s.name) ((e.tag) (e.xml1) e.xml2) =
                     <SelectA (s.name) ((e.tag) e.xml2)>;
 }

SelectA_node {
   ('@' s.name) ((s.tag e.attr) e.xml) = <GetAttr s.name e.attr>;
   (s.name)  = ;
   (s.name)  ((s.name e.attr) e.xml1) e.xml2 = 
             ((s.name e.attr) e.xml1)
             <SelectA_node (s.name) e.xml2>;
   (s.name)  ((s.tag2 e.attr) e.xml1) e.xml2 =
             <SelectA_node (s.name) e.xml2>;
 }
* =====================================================
SelectZ {
  e.1 = <Firstt <Select e.1>>;
 } 

GetAttr {
 s.name  = ;
 s.name (s.name ) e.2 = ;
 s.name (s.name s.text) e.2 = s.text;
 s.name (s.name1 e.1) e.2 = <GetAttr s.name e.2>;
 }

ValueAttr {
 (t.a e.1) e.2 = e.1 <ValueAttr e.2>;
 = ;
 }

Firstt {
  = ;
  s.1 e.2 = s.1;
  (e.1) e.2 = (e.1);
 } 

* ======================================================
*   Validate 
* ======================================================
IntDTD {
    ((s.tag e.attr) e.xml) = 
         ((<Tag s.tag e.attr>) <TUR (Q1) (e.xml) (<DTD_ s.tag>)> );
  }

TUR  {
   (s.q) ( ) (e.aut) = <Search_Empty (s.q) (e.aut)>;

   (s.q) (s.text e.xml) (e.aut) = s.text
          <TUR  <Search_PCDATA (s.q) (e.aut)> (e.xml) (e.aut)>;

*   It is local Filtr
   (s.q) (((s.tag e.attr) e.xml1) e.xml2) (e.aut) =
         <TTT  <Search (s.q) (s.tag) (e.aut)> 
               (((s.tag e.attr) e.xml1) e.xml2) (e.aut)>;
  }

TTT {
    (s.r) (((s.tag e.attr) e.xml1) e.xml2) (e.aut) =
           ((<Tag s.tag e.attr>) e.xml1)
           <TUR  (s.r) (e.xml2) (e.aut)>;
  }

Tag {
  s.tag e.attr =  <Attr (s.tag e.attr) (<DTD_ s.tag>)>;
 }

Attr {
  (s.tag) ((ATTLIST e.Attlist) e.aut) = <RI >;
  (s.tag e.attr) ((ATTLIST e.Attlist) e.aut) =
                   s.tag <Attr1 e.attr (e.Attlist)>;
  (s.tag) (e.aut) = s.tag;
 }

Attr1 {
  (s.attr e.v) e.1 ((s.attr) e.Attlist) =
                    (s.attr e.v) <Attr1  e.1 (e.Attlist)>;
  ( ) = ;
 }

RI { RI = RI; }

Search {
   (s.q) (s.tag) ((ATTLIST e.att)  e.2) = <Search (s.q) (s.tag) (e.2)>;
   (s.q) (s.tag) ((s.q PCDATA s.r) e.2) = <Search (s.q) (s.tag) (e.2)>;
   (s.q) (s.tag) ((s.q EMPTY s.r) e.2)  = <Search (s.q) (s.tag) (e.2)>;
   (s.q) (s.tag) ((s.q s.tag s.r) e.2)  = (s.r);
   (s.q) (s.tag) ((e.1) e.2)            = <Search (s.q) (s.tag) (e.2)>;
 }

Search_PCDATA {
   (s.q) ((s.q PCDATA s.r) e.2) = (s.r);
   (s.q) ((e.1) e.2) = <Search_PCDATA (s.q) (e.2)>;
 }

Search_Empty {
   (s.q) ((s.q EMPTY T ) e.2) = ;
   (s.q) ((e.1) e.2) = <Search_Empty (s.q) (e.2)>;
 }
* --------------------------------------------------------
* End   End   End   End   End   End   End   End   End
* --------------------------------------------------------