def parseSLD_v1_0_0(sourceXml, layerName, units, offset, factor, format) :
    
    gibsColorMaps = []
    
    xmldoc     = minidom.parse(sourceXml)

    #for childNode in xmldoc.documentElement.childNodes :
    for nlNode in xmldoc.documentElement.getElementsByTagName("NamedLayer") :
    
        nameNode = nlNode.getElementsByTagName("Name")[0]
        
        if nameNode.firstChild.nodeValue != layerName:
            break
        
        
        for userStyleNode in nlNode.getElementsByTagName("UserStyle"):
            # <xsd:element ref="sld:Name" minOccurs="0"/>
            # <xsd:element ref="sld:Title" minOccurs="0"/>


            for rasterSymNode in userStyleNode.getElementsByTagName("RasterSymbolizer"):
                # <xsd:element ref="sld:Name" minOccurs="0"/>
                # <xsd:element ref="sld:Title" minOccurs="0"/>
                    
                colorMapNode   = rasterSymNode.getElementsByTagName("ColorMap")[0]
                sldCMapEntries = []
                
                for colorMapEntryNode in colorMapNode.getElementsByTagName("ColorMapEntry"):
                    attrDict = dict(colorMapEntryNode.attributes.items())

                    sldCMapEntry = SLD_v1_0_0_ColorMapEntry()
                                        
                    if 'opacity' in attrDict :
                        sldCMapEntry.opacity = float(attrDict['opacity'])
                    else:
                        sldCMapEntry.opacity = 1.0
                                            
                    if 'quantity' in attrDict :
                        sldCMapEntry.quantity = float(attrDict['quantity'])
                                            
                    sldCMapEntry.rgb   = hexToRGB(str(attrDict['color']))
                    
                    sldCMapEntries.append(sldCMapEntry)

                    
                # Process the SLD entries into the XML ColorMap
                gibsCMap  = GIBS_ColorMap()
                        
                prevValue   = sldCMapEntries[0].quantity
                prevOpacity = (sldCMapEntries[0].opacity == 0.0)
                prevRGB     = sldCMapEntries[0].rgb
                        
                gibsCMap.minLabel = "" + format.format(prevValue) + ("" if not units else (" " + units))
                        
                for sldCMapEntry in sldCMapEntries[1:-1]:
                    gibsCMapEntry             = GIBS_ColorMapEntry()
                    gibsCMapEntry.rgb         = prevRGB
                    gibsCMapEntry.label       = format.format(prevValue) + " - " + format.format(sldCMapEntry.quantity) + ("" if not units else (" " + units))	
                    gibsCMapEntry.value       = [prevValue, sldCMapEntry.quantity]
                    gibsCMapEntry.sourceValue = [((prevValue - offset) / factor), ((sldCMapEntry.quantity - offset) / factor)]
                    gibsCMapEntry.transparent = prevOpacity
                            
                    gibsCMap.cmEntries.append(gibsCMapEntry)
                           
                    prevValue   = sldCMapEntry.quantity
                    prevOpacity = (sldCMapEntry.opacity == 0.0)
                    prevRGB     = sldCMapEntry.rgb

                
                
                # If the last entry has the same color as it's previous entry, then update the last 
                # colormap entry to include this upper bound
                if prevRGB == sldCMapEntries[-1].rgb:
                
                    gibsCMapEntry             = GIBS_ColorMapEntry()
                    gibsCMapEntry.rgb         = prevRGB
                    gibsCMapEntry.label       = "&gt;= " + format.format(prevValue) + ("" if not units else (" " + units))	
                    gibsCMapEntry.value       = [prevValue,sldCMapEntries[-1].quantity]
                    gibsCMapEntry.sourceValue = [prevValue, ((sldCMapEntries[-1].quantity - offset) / factor)]
                    gibsCMapEntry.transparent = prevOpacity
                    gibsCMap.cmEntries.append(gibsCMapEntry)
                
                else:
                    # Add ColorMapEntry for [-1] entry
                    gibsCMapEntry             = GIBS_ColorMapEntry()
                    gibsCMapEntry.rgb         = prevRGB
                    gibsCMapEntry.label       = format.format(prevValue) + " - " + format.format(sldCMapEntries[-1].quantity) + ("" if not units else (" " + units))	
                    gibsCMapEntry.value       = [prevValue, sldCMapEntries[-1].quantity]
                    gibsCMapEntry.sourceValue = [((prevValue - offset) / factor), ((sldCMapEntries[-1].quantity - offset) / factor)]
                    gibsCMapEntry.transparent = prevOpacity
                    gibsCMap.cmEntries.append(gibsCMapEntry)
                
                    gibsCMapEntry             = GIBS_ColorMapEntry()
                    gibsCMapEntry.rgb         = sldCMapEntries[-1].rgb
                    gibsCMapEntry.label       = format.format(sldCMapEntries[-1].quantity) + ("" if not units else (" " + units))	
                    gibsCMapEntry.value       = [sldCMapEntries[-1].quantity]
                    gibsCMapEntry.sourceValue = [((sldCMapEntries[-1].quantity - offset) / factor), "+INF"]
                    gibsCMapEntry.transparent = (sldCMapEntries[-1].opacity == 0.0)
                    gibsCMap.cmEntries.append(gibsCMapEntry)
                
                gibsCMap.maxLabel    = gibsCMap.cmEntries[-1].label
                gibsCMap.showLegend  = True
                        
                gibsColorMaps.append(gibsCMap)


    return gibsColorMaps

## END Parse SLD v1.0.0 ##



## START Parse SLD v1.1.0 ##
dataset/ETHPy150Open nasa-gibs/onearth/src/scripts/SLDtoColorMap.py/parseSLD_v1_0_0/original