Often, users may wish to create a single resource, and reuse it several times with specified variations. This is is currently possible by the use of script access to URL parameters or the <param> element in the HTML <object> element, but this approach has several drawbacks:
For this reason, this document examines some of the requirements and use cases involved in this issue, and proposes a solution for a declarative extension to SVG to fulfill these requirements. (Note: This issue is orthogonal to the CSS Variables proposal.)
For the sake of simplicity in this document, referenced parameter variables will be called variables in the general case, or <ref> elements in the specific case of a proposed solution.
One proposed solution is to specify a new SVG element, the <ref> element, which acts in a roughly similar way to a reference entity. This element would have a 'param' attribute which matches the parameter name, a 'default' attribute which provides a default value, and which is referenced by its 'id' attribute like any paint server. This differs from a paint server in that it can also be used to provide text content for a <tref> element, and attribute values for all attributes, not just presentation properties.
Advantages
Disadvantages
HTML:
<object type="image/svg+xml" data="light.svg">
<param name="color" value="red" />
<param name="text-label" value="stop" />
<param name="corners" value="0" />
</object>
SVG:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 100 100" width="100%" height="100%">
<title>Reusable Button</title>
<desc>Takes parameters from parent document's embedding element.</desc>
<defs id="defs-1">
<ref id="paramRound" param="corners" default="15"/>
<ref id="paramFill" param="color" default="blue"/>
<ref id="paramText" param="text-label" default="button"/>
<ref id="paramStroke" param="outline" default="navy"/>
</defs>
<g>
<rect id="button_rect" x="5" y="5" width="100" height="30" rx="url(#paramRound)" ry="url(#paramRound)"
fill="url(#paramFill)" stroke="url(#paramStroke)" />
<text id="button_label" x="55" y="30" text-anchor="middle"
font-size="25" fill="black" font-family="Verdana">
<tref xlink:href="#paramText" />
</text>
</g>
</svg>
Another proposed solution is to specify a new attribute value for declarative animation elements, the 'param()' attribute value. This attribute value would take an argument which matches the parameter name. The default for the attribute in question would simply be specified in the attribute's initial value.
Advantages
Disadvantages
HTML:
<object type="image/svg+xml" data="light.svg">
<param name="color" value="red" />
<param name="text-label" value="stop" />
<param name="corners" value="0" />
</object>
SVG:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 100 100" width="100%" height="100%">
<title>Reusable Button</title>
<desc>Takes parameters from parent document's embedding element.</desc>
<defs id="defs-1">
<set xlink:href="#button_rect" attributeName="fill" to="param(color)" begin="0s" fill="freeze" />
<set xlink:href="#button_rect" attributeName="stroke" to="param(outline)" begin="0s" fill="freeze" />
<set xlink:href="#button_rect" attributeName="rx" to="param(corners)" begin="0s" fill="freeze" />
<set xlink:href="#button_rect" attributeName="ry" to="param(corners)" begin="0s" fill="freeze" />
<set xlink:href="#button_label" attributeName="???" to="param(text-label)" begin="0s" fill="freeze" />
</defs>
<g>
<rect id="button_rect" x="5" y="5" width="100" height="30" rx="15" ry="15"
fill="blue" stroke="navy" />
<text id="button_label" x="55" y="30" text-anchor="middle"
font-size="25" fill="black" font-family="Verdana"> </text>
</g>
</svg>
Comments and questions may be sent to schepers@w3.org. Some open questions and details are: