Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7daf2f598d0ab8423b59c4eed8a93f21ccf5b4bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module XML2Book;
create OUT : Book from IN : XML;

helper context XML!Element def: getAttrVal(name : String) : String =
	self.children->select(c | c.oclIsKindOf(XML!Attribute) and c.name = name)->first().value;

rule Book {
	from
		e : XML!Element (
			e.name = 'book'
		)
	to
		b : Book!Book (
			title <- e.getAttrVal('title'),
			chapters <- e.children->select(c | c.oclIsKindOf(XML!Element))->asSequence()
		)
}

rule Chapter {
	from
		e : XML!Element (
			e.name = 'chapter'
		)
	to
		c : Book!Chapter (
			title <- e.getAttrVal('title'),
			nbPages <- e.getAttrVal('nbPages').toInteger(),
			author <- e.getAttrVal('author')
		)
}

Back to the top