YML 2.0.32: Generating attributes with macros
... i.e. for processing UML in XMI. I added the possibility to generate attributes based on text parameters called "macros". An example:
include yslt.yml2
decl UML is textstylesheet(
xmlns:uml="http://schema.omg.org/spec/UML/2.1",
xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
) {
output *output;
const "space", !"'" + " " * 200 + "'"!;
param "autoindent", 4;
template "text()";
template "/" apply "xmi:XMI/uml:Model/packagedElement", 0;
content;
};
decl Package is template(
%match="true()",
match="packagedElement[@xmi:type='uml:Package' and (%match)]"
);
decl Class is template(
%match="true()",
match="packagedElement[@xmi:type='uml:Class' and (%match)]"
);
decl Attribute is template(
%match="true()",
match="ownedAttribute[@xmi:type='uml:Property' and
type/@xmi:type='uml:PrimitiveType' and (%match)]"
);
This lets you process XMI containing UML like in this simple sample:
include uml.yml2
UML {
Package {
param "name", "''";
if "$name=''" apply "packagedElement",
0 { with "name", "@name"; }
if "$name!=''" apply "packagedElement",
0 { with "name", "concat($name, '_', @name)"; }
}
Class {
param "name";
| CREATE TABLE «$name»_«@name» (
apply "ownedAttribute";
| );
}
Attribute {
0> «@name»
choose {
when "type/@href='http://schema.omg.org/spec/UML/2.1/uml.xml#String'"
> VARCHAR
// [...] for other types, extend when clauses
}
if "position()!=last()" > ,
>
}
}
For more information, see the YML documentation.
publiziert Wed, 25 Mar 2009 14:06:16 +0100