title: Can you reuse fragments of XML (in some kind of variables/references way)?
body: <p>I am using <a href="http://en.wikipedia.org/wiki/Styled_Layer_Descriptor" rel="nofollow noreferrer">SLD</a> to style output from my geoserver. I have couple types of objects to be displayed. Each type have different icons, but text description is generated from the same information (text field in the database). I cannot use object_type as image name because you cannot use variable in image name (or I do not know how to do it...). So I Have SLD like (without unimportant parts):</p>
  
  <pre><code>&lt;StyledLayerDescriptor&gt;
    &lt;NamedLayer&gt;
      &lt;UserStyle&gt;
        &lt;FeatureTypeStyle&gt;
          &lt;Rule&gt;
            &lt;Filter&gt;
              &lt;PropertyIsEqualTo&gt;
                &lt;PropertyName&gt;object_type&lt;/PropertyName&gt;
                &lt;Literal&gt;1&lt;/Literal&gt;
              &lt;/PropertyIsEqualTo&gt;
            &lt;/Filter&gt;
            &lt;PointSymbolizer&gt;
              &lt;Graphic&gt;
                &lt;ExternalGraphic&gt;
                  &lt;OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="/images/1.png" /&gt;
                  &lt;Format&gt;image/png&lt;/Format&gt;
                &lt;/ExternalGraphic&gt;
                &lt;Size&gt;16&lt;/Size&gt;
                &lt;Opacity&gt;1&lt;/Opacity&gt;
              &lt;/Graphic&gt;
            &lt;/PointSymbolizer&gt;
            &lt;TextSymbolizer&gt;
              &lt;Label&gt;
                &lt;ogc:PropertyName&gt;name&lt;/ogc:PropertyName&gt;
              &lt;/Label&gt;
              &lt;Font&gt;
                &lt;CssParameter name="font-family"&gt;Times New Roman&lt;/CssParameter&gt;
                &lt;CssParameter name="font-style"&gt;Normal&lt;/CssParameter&gt;
                &lt;CssParameter name="font-size"&gt;12&lt;/CssParameter&gt;
              &lt;/Font&gt;
              &lt;Fill&gt;
                &lt;CssParameter name="fill"&gt;#110011&lt;/CssParameter&gt;
                &lt;CssParameter name="fill-opacity"&gt;1&lt;/CssParameter&gt;
              &lt;/Fill&gt;
              &lt;Halo /&gt;
            &lt;/TextSymbolizer&gt;
          &lt;/Rule&gt;
  
          &lt;Rule&gt;
            &lt;Filter&gt;
              &lt;PropertyIsEqualTo&gt;
                &lt;PropertyName&gt;object_type&lt;/PropertyName&gt;
                &lt;Literal&gt;2&lt;/Literal&gt;
              &lt;/PropertyIsEqualTo&gt;
            &lt;/Filter&gt;
            &lt;PointSymbolizer&gt;
              &lt;Graphic&gt;
                &lt;ExternalGraphic&gt;
                  &lt;OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="/images/2.png" /&gt;
                  &lt;Format&gt;image/png&lt;/Format&gt;
                &lt;/ExternalGraphic&gt;
                &lt;Size&gt;16&lt;/Size&gt;
                &lt;Opacity&gt;1&lt;/Opacity&gt;
              &lt;/Graphic&gt;
            &lt;/PointSymbolizer&gt;
            &lt;TextSymbolizer&gt;
              &lt;Label&gt;
                &lt;ogc:PropertyName&gt;name&lt;/ogc:PropertyName&gt;
              &lt;/Label&gt;
              &lt;Font&gt;
                &lt;CssParameter name="font-family"&gt;Times New Roman&lt;/CssParameter&gt;
                &lt;CssParameter name="font-style"&gt;Normal&lt;/CssParameter&gt;
                &lt;CssParameter name="font-size"&gt;12&lt;/CssParameter&gt;
              &lt;/Font&gt;
              &lt;Fill&gt;
                &lt;CssParameter name="fill"&gt;#110011&lt;/CssParameter&gt;
                &lt;CssParameter name="fill-opacity"&gt;1&lt;/CssParameter&gt;
              &lt;/Fill&gt;
              &lt;Halo /&gt;
            &lt;/TextSymbolizer&gt;
          &lt;/Rule&gt;
        &lt;/FeatureTypeStyle&gt;
      &lt;/UserStyle&gt;
    &lt;/NamedLayer&gt;
  &lt;/StyledLayerDescriptor&gt;
  </code></pre>
  
  <p>And the thing I'd love to do would be writing TextSymbolizer once and using it in two or more places... I have not heard of anything like that in XML, but maybe you have? :-)</p>
  
  <p>One solution that comes to me, is to write some very simple generator (xml.erb? :P) and let it generate XML...</p>