Home News style sheet macro parameters

style sheet macro parameters

By Graham Asher on 30 April 2010

For a long time I resisted the added complexity of macro parameters. I reasoned that I did not want to encourage complicated style sheets or implement a general programming language inside CartoType's style sheet system. Then one day a client showed me a vast style sheet containing many repeated macros, all identical except for a couple of values. Traffic density for all permutations of density and road type was shown by highlights of varying color, width, and distance from the main line.

I was convinced: how much simpler to have just a single macro with three parameters. Luckily, implementation was simpler than I expected. And here is how you use parameters with a macro:

<!-- define the macro -->
<macro id='highlight-macro'>
	<highlight width='~width~' distance='~distance~' fill='~fill~'>
		<repeatedSymbol path='#arrow' gap='2000' fill='black'/>
	</highlight>
</macro>
...
<!-- use the macro -->
<macro ref='highlight-macro' width='80%' distance='10%' fill='green'/>

So the rules are: when you define the macro, parameters have ~ before and after their names in the macro code; and when you use the macro, define all the parameters as attributes.