I am trying to clean my GeoServer deleting some redundant SLD Styles.

All this styles work in the same way, they assign some image (different for every style, which name is hardcoded in every style) to every point in the layer, passing the image as an OnlineResource, later as a ExternalGraphic and finally as a PointSimbolizer. I want to replace all this styles by one generic style who have the image name as a parameter.

TODO: Example

In my First attempt I tried to replace the hard coded name of the image using the ogc:Function name="env" and passing the name as a WMS parameter, but this fail because the name is in the OnlineResource tag.

My Second attempt whas to use a CQL_FILTER to pass the name, but i cant add the name as a feature of the layer.

      <Title>Potencial hidráulico</Title>
           <ExternalGraphic xmlns="http://www.opengis.net/sld" xmlns:xlink="http://www.w3.org/1999/xlink">
             <OnlineResource xlink:type="simple" xlink:href="${IMG}"  />

Calling with this URL:[workspace]/wms?&CQL_FILTER=IMG=%27gen_hiroelectrica.png%27&service=WMS&version=1.1.0&request=GetMap&layers=[workspace]%3A[layer]

Giving me this error:

2022-06-06 11:43:24,712 ERROR [geoserver.ows] - org.geoserver.platform.ServiceException: The requested Style can not be used with this layer. The style specifies an attribute named 'IMG', not found in the '[workspace]:[layer]' layer

Are any of those way correct? There is other alternative way to parameterize the name of the image? It is even possible (or recommended) to replace all the redundant styles by one generic style?

  • Please show us what you tried and what went wrong
    – Ian Turton
    Jun 3 at 17:17
  • I am going to add the example when I come back to the office this monday. Thanks for the comment. Jun 3 at 18:06

1 Answer 1


If I get your request correctly, you're looking for a special customization of SLD (not standard) that is called "dynamic symbolizers" in GeoServer. See this old blog post about it (very old, SLD got ruined during the various migrations in the last 14 years):


In short, functionalty allows to embed a generic CQL expression inside the URL of a external graphic:


There are however downsides to this approach: GeoServer will not be able to generate a legend image any more, as the contents of it now depend dynamically on the values of your data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.