Monday, June 11, 2012

Convert GeoMedia styles to geotools SLD format - Solution

If you have stored GeoMedia legend entry styles in an XML file in a specific format, you can directly convert them to SLD using XSLT.

I have written a .Net command for GeoMedia which iterates over all legend entries (thematic legends are not included) and stores all style properties in an XML file. Later using java, I have processed that xml based on connection and created separate sub-xml. Then applied the xslt over each subxml to generate the SLD file. Now I'm able to load the data file (MDB) along with style in uDig using the SLD.

Initially I was searching for such template over web to generate SLD from any known format but didn't find one. So I have written my own. You can find lots of sample to generate a subxml from an existing big xml file and how to use XSLT on-the-fly to get an output xml. See the XSLT below -

<?xml version="1.0" encoding="UTF-8"?>
<!--smaity - 12-June-2012
Style transformation template for GeoMedia style properties to OGC SLD format. Copyright All rights reserved. mrDOTsajalATgmailDOTcom-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs fn xsl">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 <xsl:template match="/">
  <xsl:for-each select="Connection">
   <xsl:if test="@type = 'Vector'">
    <sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
     <sld:Name>
      <xsl:value-of select="name"/>
     </sld:Name>
     <xsl:for-each select="Layers">
      <xsl:for-each select="Layer">
       <sld:UserLayer>
        <sld:Name>
         <xsl:value-of select="@name"/>
        </sld:Name>
        <sld:LayerFeatureConstraints>
         <sld:FeatureTypeConstraint/>
        </sld:LayerFeatureConstraints>
        <sld:UserStyle>
         <sld:Name>Default Styler</sld:Name>
         <sld:Title/>
         <sld:FeatureTypeStyle>
          <sld:Name>
           <xsl:value-of select="@name"/>
          </sld:Name>
          <sld:FeatureTypeName>Feature</sld:FeatureTypeName>
          <sld:SemanticTypeIdentifier>generic:geometry</sld:SemanticTypeIdentifier>
          <xsl:for-each select="Style">
           <xsl:if test="Displayable='True'">
            <sld:Rule>
             <sld:MaxScaleDenominator>1.7976931348623157E308</sld:MaxScaleDenominator>
             <sld:Name>Default</sld:Name>
             <xsl:choose>
              <xsl:when test="StyleType='Symbol Style'">
               <xsl:if test="SymbolRendererName=''">
                <sld:PointSymbolizer>
                 <sld:Graphic>
                  <sld:Mark>
                   <sld:WellKnownName>circle</sld:WellKnownName>
                   <xsl:if test="Displayable='True'">
                    <sld:Fill>
                     <sld:CssParameter name="fill">
                      <xsl:variable name="color">
                       <xsl:value-of select="empty"/>
                       <xsl:call-template name="ConvertDecToHex">
                        <xsl:with-param name="index">
                         <xsl:value-of select="OverrideColor"/>
                        </xsl:with-param>
                       </xsl:call-template>
                      </xsl:variable>
                      <xsl:variable name="finalcolor">
                       <xsl:choose>
                        <xsl:when test="string-length(string($color)) = 6">
                         <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                        </xsl:when>
                        <xsl:when test="string-length(string($color)) = 4">
                         <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                        </xsl:when>
                        <xsl:when test="string-length(string($color)) = 2">
                         <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                        </xsl:when>
                        <xsl:otherwise>
                         <xsl:value-of select="concat('00','00','00')"/>
                        </xsl:otherwise>
                       </xsl:choose>
                      </xsl:variable>
                      <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                      </ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="fill-opacity">
                      <ogc:Literal>
                       <xsl:value-of select="1 - Translucency div 100"/>
                      </ogc:Literal>
                     </sld:CssParameter>
                    </sld:Fill>
                    <sld:Stroke>
                     <sld:CssParameter name="stroke">
                      <xsl:variable name="color">
                       <xsl:call-template name="ConvertDecToHex">
                        <xsl:with-param name="index">
                         <xsl:value-of select="OverrideColor"/>
                        </xsl:with-param>
                       </xsl:call-template>
                      </xsl:variable>
                      <xsl:variable name="finalcolor">
                       <xsl:choose>
                        <xsl:when test="string-length(string($color)) = 6">
                         <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                        </xsl:when>
                        <xsl:when test="string-length(string($color)) = 4">
                         <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                        </xsl:when>
                        <xsl:when test="string-length(string($color)) = 2">
                         <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                        </xsl:when>
                        <xsl:otherwise>
                         <xsl:value-of select="concat('00','00','00')"/>
                        </xsl:otherwise>
                       </xsl:choose>
                      </xsl:variable>
                      <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                      </ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="stroke-linecap">
                      <ogc:Literal>butt</ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="stroke-linejoin">
                      <ogc:Literal>miter</ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="stroke-opacity">
                      <ogc:Literal>1.0</ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="stroke-width">
                      <ogc:Literal>
                       <xsl:value-of select="Width div 100 div 0.2645"/>
                      </ogc:Literal>
                     </sld:CssParameter>
                     <sld:CssParameter name="stroke-dashoffset">
                      <ogc:Literal>0.0</ogc:Literal>
                     </sld:CssParameter>
                    </sld:Stroke>
                   </xsl:if>
                  </sld:Mark>
                  <sld:Opacity>
                   <ogc:Literal>
                    <xsl:value-of select="1-Translucency div 100"/>
                   </ogc:Literal>
                  </sld:Opacity>
                  <sld:Size>
                   <ogc:Literal>
                    <xsl:value-of select="Size div 100 div 0.2645"/>
                   </ogc:Literal>
                  </sld:Size>
                  <sld:Rotation>
                   <ogc:Literal>
                    <xsl:value-of select="Rotation"/>
                   </ogc:Literal>
                  </sld:Rotation>
                 </sld:Graphic>
                </sld:PointSymbolizer>
               </xsl:if>
              </xsl:when>
              <xsl:when test="StyleType='Text Style'">
               <xsl:if test="Displayable='True'">
                <sld:PointSymbolizer>
                 <sld:Graphic>
                  <sld:Mark>
                   <sld:WellKnownName>square</sld:WellKnownName>
                  </sld:Mark>
                  <sld:Opacity>
                   <ogc:Literal>1.0</ogc:Literal>
                  </sld:Opacity>
                  <sld:Size>
                   <ogc:Literal>-1.0</ogc:Literal>
                  </sld:Size>
                  <sld:Rotation>
                   <ogc:Literal>0.0</ogc:Literal>
                  </sld:Rotation>
                 </sld:Graphic>
                </sld:PointSymbolizer>
                <sld:TextSymbolizer>
                 <sld:Label>
                  <ogc:PropertyName>Text</ogc:PropertyName>
                 </sld:Label>
                 <sld:Font>
                  <sld:CssParameter name="font-family">
                   <ogc:Literal>
                    <xsl:value-of select="FontName"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-size">
                   <ogc:Literal>
                    <xsl:value-of select="FontSize div 100 div 0.2645"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-style">
                   <xsl:choose>
                    <xsl:when test="FontItalic='True'">
                     <ogc:Literal>italic</ogc:Literal>
                    </xsl:when>
                    <xsl:otherwise>
                     <ogc:Literal>normal</ogc:Literal>
                    </xsl:otherwise>
                   </xsl:choose>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-weight">
                   <xsl:choose>
                    <xsl:when test="FontBold='True'">
                     <ogc:Literal>Bold</ogc:Literal>
                    </xsl:when>
                    <xsl:otherwise>
                     <ogc:Literal>normal</ogc:Literal>
                    </xsl:otherwise>
                   </xsl:choose>
                  </sld:CssParameter>
                 </sld:Font>
                 <sld:LabelPlacement>
                  <sld:PointPlacement>
                   <sld:AnchorPoint>
                    <sld:AnchorPointX>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:AnchorPointX>
                    <sld:AnchorPointY>
                     <ogc:Literal>0.5</ogc:Literal>
                    </sld:AnchorPointY>
                   </sld:AnchorPoint>
                   <sld:Displacement>
                    <sld:DisplacementX>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:DisplacementX>
                    <sld:DisplacementY>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:DisplacementY>
                   </sld:Displacement>
                   <sld:Rotation>
                    <ogc:Sub>
                     <ogc:Literal>360.0</ogc:Literal>
                     <ogc:PropertyName>Angle</ogc:PropertyName>
                    </ogc:Sub>
                   </sld:Rotation>
                  </sld:PointPlacement>
                 </sld:LabelPlacement>
                 <sld:Fill>
                  <sld:CssParameter name="fill">
                   <xsl:variable name="color">
                    <xsl:call-template name="ConvertDecToHex">
                     <xsl:with-param name="index">
                      <xsl:value-of select="Color"/>
                     </xsl:with-param>
                    </xsl:call-template>
                   </xsl:variable>
                   <xsl:variable name="finalcolor">
                    <xsl:choose>
                     <xsl:when test="string-length(string($color)) = 6">
                      <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 4">
                      <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 2">
                      <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                     </xsl:when>
                     <xsl:otherwise>
                      <xsl:value-of select="concat('00','00','00')"/>
                     </xsl:otherwise>
                    </xsl:choose>
                   </xsl:variable>
                   <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="fill-opacity">
                   <ogc:Literal>
                    <xsl:value-of select="1 - Translucency div 100"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                 </sld:Fill>
                 <VendorOption name="spaceAround">-1</VendorOption>
                 <VendorOption name="conflictResolution">false</VendorOption>
                </sld:TextSymbolizer>
               </xsl:if>
              </xsl:when>
              <xsl:when test="StyleType='Simple Line Style'">
               <xsl:if test="Displayable='True'">
                <sld:LineSymbolizer>
                 <sld:Stroke>
                  <sld:CssParameter name="stroke">
                   <xsl:variable name="color">
                    <xsl:call-template name="ConvertDecToHex">
                     <xsl:with-param name="index">
                      <xsl:value-of select="Color"/>
                     </xsl:with-param>
                    </xsl:call-template>
                   </xsl:variable>
                   <xsl:variable name="finalcolor">
                    <xsl:choose>
                     <xsl:when test="string-length(string($color)) = 6">
                      <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 4">
                      <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 2">
                      <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                     </xsl:when>
                     <xsl:otherwise>
                      <xsl:value-of select="concat('00','00','00')"/>
                     </xsl:otherwise>
                    </xsl:choose>
                   </xsl:variable>
                   <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="stroke-linecap">
                   <ogc:Literal>butt</ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="stroke-linejoin">
                   <ogc:Literal>miter</ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="stroke-opacity">
                   <ogc:Literal>
                    <xsl:value-of select="1 - Translucency div 100"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="stroke-width">
                   <ogc:Literal>
                    <xsl:value-of select="Width div 100 div 0.2645"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="stroke-dashoffset">
                   <ogc:Literal>0</ogc:Literal>
                  </sld:CssParameter>
                 </sld:Stroke>
                </sld:LineSymbolizer>
               </xsl:if>
              </xsl:when>
              <xsl:when test="StyleType='Font Style'">
               <xsl:if test="Displayable='True'">
                <sld:TextSymbolizer>
                 <sld:Label>
                  <ogc:PropertyName>Text</ogc:PropertyName>
                 </sld:Label>
                 <sld:Font>
                  <sld:CssParameter name="font-family">
                   <ogc:Literal>
                    <xsl:value-of select="FontName"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-size">
                   <ogc:Literal>
                    <xsl:value-of select="FontSize div 100 div 0.2645"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-style">
                   <xsl:choose>
                    <xsl:when test="FontItalic='True'">
                     <ogc:Literal>italic</ogc:Literal>
                    </xsl:when>
                    <xsl:otherwise>
                     <ogc:Literal>normal</ogc:Literal>
                    </xsl:otherwise>
                   </xsl:choose>
                  </sld:CssParameter>
                  <sld:CssParameter name="font-weight">
                   <xsl:choose>
                    <xsl:when test="FontBold='True'">
                     <ogc:Literal>Bold</ogc:Literal>
                    </xsl:when>
                    <xsl:otherwise>
                     <ogc:Literal>normal</ogc:Literal>
                    </xsl:otherwise>
                   </xsl:choose>
                  </sld:CssParameter>
                 </sld:Font>
                 <sld:LabelPlacement>
                  <sld:PointPlacement>
                   <sld:AnchorPoint>
                    <sld:AnchorPointX>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:AnchorPointX>
                    <sld:AnchorPointY>
                     <ogc:Literal>0.5</ogc:Literal>
                    </sld:AnchorPointY>
                   </sld:AnchorPoint>
                   <sld:Displacement>
                    <sld:DisplacementX>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:DisplacementX>
                    <sld:DisplacementY>
                     <ogc:Literal>0.0</ogc:Literal>
                    </sld:DisplacementY>
                   </sld:Displacement>
                   <sld:Rotation>
                    <ogc:Sub>
                     <ogc:Literal>360.0</ogc:Literal>
                     <ogc:PropertyName>Angle</ogc:PropertyName>
                    </ogc:Sub>
                   </sld:Rotation>
                  </sld:PointPlacement>
                 </sld:LabelPlacement>
                 <sld:Fill>
                  <sld:CssParameter name="fill">
                   <xsl:variable name="color">
                    <xsl:call-template name="ConvertDecToHex">
                     <xsl:with-param name="index">
                      <xsl:value-of select="Color"/>
                     </xsl:with-param>
                    </xsl:call-template>
                   </xsl:variable>
                   <xsl:variable name="finalcolor">
                    <xsl:choose>
                     <xsl:when test="string-length(string($color)) = 6">
                      <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 4">
                      <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                     </xsl:when>
                     <xsl:when test="string-length(string($color)) = 2">
                      <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                     </xsl:when>
                     <xsl:otherwise>
                      <xsl:value-of select="concat('00','00','00')"/>
                     </xsl:otherwise>
                    </xsl:choose>
                   </xsl:variable>
                   <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                  <sld:CssParameter name="fill-opacity">
                   <ogc:Literal>
                    <xsl:value-of select="1 - Translucency div 100"/>
                   </ogc:Literal>
                  </sld:CssParameter>
                 </sld:Fill>
                 <VendorOption name="spaceAround">-1</VendorOption>
                 <VendorOption name="conflictResolution">false</VendorOption>
                </sld:TextSymbolizer>
               </xsl:if>
              </xsl:when>
              <xsl:when test="StyleType='Area Style'">
               <xsl:if test="Displayable='True'">
                <sld:PolygonSymbolizer>
                 <xsl:for-each select="Styles">
                  <xsl:choose>
                   <xsl:when test="StyleType='Boundary Styles'">
                    <xsl:if test="Displayable='True'">
                     <xsl:for-each select="Style">
                      <xsl:choose>
                       <xsl:when test="StyleType='Simple Line Style'">
                        <xsl:if test="Displayable='True'">
                         <sld:Stroke>
                          <sld:CssParameter name="stroke">
                           <xsl:variable name="color">
                            <xsl:call-template name="ConvertDecToHex">
                             <xsl:with-param name="index">
                              <xsl:value-of select="Color"/>
                             </xsl:with-param>
                            </xsl:call-template>
                           </xsl:variable>
                           <xsl:variable name="finalcolor">
                            <xsl:choose>
                             <xsl:when test="string-length(string($color)) = 6">
                              <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                             </xsl:when>
                             <xsl:when test="string-length(string($color)) = 4">
                              <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                             </xsl:when>
                             <xsl:when test="string-length(string($color)) = 2">
                              <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                             </xsl:when>
                             <xsl:otherwise>
                              <xsl:value-of select="concat('00','00','00')"/>
                             </xsl:otherwise>
                            </xsl:choose>
                           </xsl:variable>
                           <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                           </ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="stroke-linecap">
                           <ogc:Literal>butt</ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="stroke-linejoin">
                           <ogc:Literal>miter</ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="stroke-opacity">
                           <ogc:Literal>1</ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="stroke-width">
                           <ogc:Literal>
                            <xsl:value-of select="Width div 100 div 0.2645"/>
                           </ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="stroke-dashoffset">
                           <ogc:Literal>0</ogc:Literal>
                          </sld:CssParameter>
                         </sld:Stroke>
                        </xsl:if>
                       </xsl:when>
                       <xsl:otherwise>
                        <sld:Stroke>
                         <sld:CssParameter name="stroke">
                          <xsl:variable name="color">
                           <xsl:call-template name="ConvertDecToHex">
                            <xsl:with-param name="index">
                             <xsl:value-of select="Color"/>
                            </xsl:with-param>
                           </xsl:call-template>
                          </xsl:variable>
                          <xsl:variable name="finalcolor">
                           <xsl:choose>
                            <xsl:when test="string-length(string($color)) = 6">
                             <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                            </xsl:when>
                            <xsl:when test="string-length(string($color)) = 4">
                             <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                            </xsl:when>
                            <xsl:when test="string-length(string($color)) = 2">
                             <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                            </xsl:when>
                            <xsl:otherwise>
                             <xsl:value-of select="concat('00','00','00')"/>
                            </xsl:otherwise>
                           </xsl:choose>
                          </xsl:variable>
                          <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                          </ogc:Literal>
                         </sld:CssParameter>
                         <sld:CssParameter name="stroke-linecap">
                          <ogc:Literal>butt</ogc:Literal>
                         </sld:CssParameter>
                         <sld:CssParameter name="stroke-linejoin">
                          <ogc:Literal>miter</ogc:Literal>
                         </sld:CssParameter>
                         <sld:CssParameter name="stroke-opacity">
                          <ogc:Literal>1</ogc:Literal>
                         </sld:CssParameter>
                         <sld:CssParameter name="stroke-width">
                          <ogc:Literal>
                           <xsl:value-of select="Width div 100 div 0.2645"/>
                          </ogc:Literal>
                         </sld:CssParameter>
                         <sld:CssParameter name="stroke-dashoffset">
                          <ogc:Literal>0</ogc:Literal>
                         </sld:CssParameter>
                        </sld:Stroke>
                       </xsl:otherwise>
                      </xsl:choose>
                     </xsl:for-each>
                    </xsl:if>
                   </xsl:when>
                   <xsl:when test="StyleType='Fill Styles'">
                    <xsl:if test="Displayable='True'">
                     <xsl:for-each select="Style">
                      <xsl:choose>
                       <xsl:when test="StyleType='Simple Fill Style'">
                        <xsl:if test="Displayable='True'">
                         <sld:Fill>
                          <sld:CssParameter name="fill">
                           <xsl:variable name="color">
                            <xsl:call-template name="ConvertDecToHex">
                             <xsl:with-param name="index">
                              <xsl:value-of select="Color"/>
                             </xsl:with-param>
                            </xsl:call-template>
                           </xsl:variable>
                           <xsl:variable name="finalcolor">
                            <xsl:choose>
                             <xsl:when test="string-length(string($color)) = 6">
                              <xsl:value-of select="concat(substring($color,5,2),substring($color,3,2),substring($color,1,2))"/>
                             </xsl:when>
                             <xsl:when test="string-length(string($color)) = 4">
                              <xsl:value-of select="concat(substring($color,3,2),substring($color,1,2),'00')"/>
                             </xsl:when>
                             <xsl:when test="string-length(string($color)) = 2">
                              <xsl:value-of select="concat(substring($color,1,2),'00','00')"/>
                             </xsl:when>
                             <xsl:otherwise>
                              <xsl:value-of select="concat('00','00','00')"/>
                             </xsl:otherwise>
                            </xsl:choose>
                           </xsl:variable>
                           <ogc:Literal>#<xsl:value-of select="$finalcolor"/>
                           </ogc:Literal>
                          </sld:CssParameter>
                          <sld:CssParameter name="fill-opacity">
                           <ogc:Literal>
                            <xsl:value-of select="1-Translucency div 100"/>
                           </ogc:Literal>
                          </sld:CssParameter>
                         </sld:Fill>
                        </xsl:if>
                       </xsl:when>
                      </xsl:choose>
                     </xsl:for-each>
                    </xsl:if>
                   </xsl:when>
                  </xsl:choose>
                 </xsl:for-each>
                </sld:PolygonSymbolizer>
               </xsl:if>
              </xsl:when>
             </xsl:choose>
            </sld:Rule>
           </xsl:if>
          </xsl:for-each>
         </sld:FeatureTypeStyle>
        </sld:UserStyle>
       </sld:UserLayer>
      </xsl:for-each>
     </xsl:for-each>
    </sld:StyledLayerDescriptor>
   </xsl:if>
  </xsl:for-each>
 </xsl:template>
 <xsl:template name="ConvertDecToHex">
  <xsl:param name="index"/>
  <xsl:if test="$index > 0">
   <xsl:call-template name="ConvertDecToHex">
    <xsl:with-param name="index" select="floor($index div 16)"/>
   </xsl:call-template>
   <xsl:choose>
    <xsl:when test="$index mod 16 &lt; 10">
     <xsl:value-of select="$index mod 16"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:choose>
      <xsl:when test="$index mod 16 = 10">A</xsl:when>
      <xsl:when test="$index mod 16 = 11">B</xsl:when>
      <xsl:when test="$index mod 16 = 12">C</xsl:when>
      <xsl:when test="$index mod 16 = 13">D</xsl:when>
      <xsl:when test="$index mod 16 = 14">E</xsl:when>
      <xsl:when test="$index mod 16 = 15">F</xsl:when>
      <xsl:otherwise>A</xsl:otherwise>
     </xsl:choose>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>