]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.data/examples/XMLTransformationTest2.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.data / examples / XMLTransformationTest2.scl
diff --git a/bundles/org.simantics.scl.data/examples/XMLTransformationTest2.scl b/bundles/org.simantics.scl.data/examples/XMLTransformationTest2.scl
new file mode 100644 (file)
index 0000000..18041bc
--- /dev/null
@@ -0,0 +1,32 @@
+import "Data/XML"\r
+\r
+sexOfRole "father"   = "Male"\r
+sexOfRole "mother"   = "Female"\r
+sexOfRole "son"      = "Male"\r
+sexOfRole "daughter" = "Female"\r
+\r
+mapping relation RootMapping Element Element\r
+\r
+rule PersonRule where\r
+    @when\r
+    RootMapping ?families ?persons\r
+    \r
+    @from\r
+    Element ?families "Family" ?family\r
+    Attribute ?family "lastName" ?lastName\r
+    Element ?family ?role ?familyMember\r
+    Attribute ?familyMember "firstName" ?firstName\r
+    \r
+    @to\r
+    Element ?persons (sexOfRole ?role) ?person\r
+    Attribute ?person "fullName" (?firstName + " " + ?lastName)\r
+    \r
+main :: [String] -> <Proc> ()\r
+main [fileName] = do\r
+    doc = parseFile fileName\r
+    doc2 = parseString "<Persons/>"\r
+\r
+    transformation OneShotForward where\r
+        RootMapping (rootElementOf doc) (rootElementOf doc2)\r
+    \r
+    print $ outputString doc2\r