GeoServer's renderer uses, and is basically built around, the SLD (Styled Layer Descriptor) specification. SLD is an XML (Extensible Markup Language) extension specified by OGC. It allows rich representation of the underlying spatial data regardless of their type. As SLD is XML based, it is a structured text using tags, attributes, and values. In order to understand SLD better, let's go through the description of the style we opened before.
The first line in grey describes that the content as a valid XML document of version 1.0 with a UTF-8 character encoding. In the other lines, we can see the body of the SLD. As in every valid XML document, most of the elements have an opening (<TagName>) and a closing (</TagName>) tag. Between the two tags, the content of the element is described, whether it is a simple value, or a group of other elements. The body tag of an SLD document is <StyledLayerDescriptor>, which we can see in the second, and the last line. Opening tags can also have some attributes if applicable (for example, <StyledLayerDescriptor version="1.0.0">). The attributes of the <StyledLayerDescriptor> element are static, and out of concern, as they will be automatically generated if we generate a template for our new style. There are some additional elements we should understand to create a basic style. They are as follows:
- <Name>: The name of the parent element. It is mandatory for the <StyledLayerDescriptor> element, but not relevant (that is, it can be anything). It can be also used to describe some other elements optionally.
- <UserStyle>: A mandatory child of the <StyledLayerDescriptor> element, which contains the style definition.
- <FeatureTypeStyle>: At least one of this element should be present in a <UserStyle> element. It groups different rules of styling applied in a single rendering pass. Multiple elements of this kind can achieve complex styles.
- <Rule>: A single set of rules grouping filters and corresponding symbology.
- <ogc:Filter>: A filter element in a <Rule> element describing a subset of the vector layer which should be styled in the rule.
- <PointSymbolizer>, <LineSymbolizer>, <PolygonSymbolizer>, <TextSymbolizer>, <RasterSymbolizer>: Elements residing in a <Rule> element describing a single symbol of the underlying spatial data in the rule.
- <Fill>, <Stroke>, <Label>, <Font>, <Mark>, <ColorMap>: Children of the symbolizer elements describing the appropriate properties of the parent symbol. For example, a <PolygonSymbolizer> can have <Fill> and <Stroke> children, but cannot have a <Mark> child, as it describes a point symbol.
- <CssParameter>: An element describing a single parameter of a symbol's aspect. For example, a <Stroke> element can contain a <CssParameter name="stroke"> element describing the stroke's color, and a <CssParameter name="stroke-width"> element describing its width.
- <ogc:Literal>: An element containing a value. It is usually used as a child of an <ogc:Filter> element to provide a value.