sascha@516: <?xml version="1.0" encoding="UTF-8"?>
sascha@520: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
sascha@520:   <!--
sascha@516:     palette2qgis.xsl
sascha@516:     ================
sascha@516:     Transforms palette XML files into QGIS style files. Useful
sascha@516:     to display "Horizontalschnitte" with the right colors.
sascha@516: 
sascha@516:     Tested with Quantum GIS 1.4.0-Enceladus.
sascha@516: 
sascha@516:     usage: xsltproc palette2qgis.xsl palette.xml > style.qml
sascha@516: 
sascha@516:     Author: Sascha L. Teichmann (sascha.teichmann@intevation.de)
sascha@516:     -->
sascha@520:   <xsl:output
sascha@520:        method="xml"
sascha@520:        doctype-system="PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'"/>
sascha@516: 
sascha@520:   <xsl:template name="hex2number">
sascha@520:     <xsl:param name="hex"/>
sascha@520:     <xsl:choose>
sascha@520:         <xsl:when test="string-length($hex) &lt; 1">
sascha@520:             <xsl:value-of select="0"/>
sascha@520:         </xsl:when>
sascha@520:         <xsl:otherwise>
sascha@520:             <xsl:variable
sascha@520:                 name="x" 
sascha@520:                 select="translate(substring($hex, string-length($hex), 1), 'ABCDEF', 'abcdef')"/>
sascha@520:             <xsl:variable name="last">
sascha@520:               <xsl:choose>
sascha@516:                 <xsl:when test="$x = 'a'">10</xsl:when>
sascha@516:                 <xsl:when test="$x = 'b'">11</xsl:when>
sascha@516:                 <xsl:when test="$x = 'c'">12</xsl:when>
sascha@516:                 <xsl:when test="$x = 'd'">13</xsl:when>
sascha@516:                 <xsl:when test="$x = 'e'">14</xsl:when>
sascha@516:                 <xsl:when test="$x = 'f'">15</xsl:when>
sascha@520:                 <xsl:otherwise>
sascha@520:                   <xsl:value-of select="$x"/>
sascha@520:                 </xsl:otherwise>
sascha@520:               </xsl:choose>
sascha@520:             </xsl:variable>
sascha@520:             <xsl:variable name="rest">
sascha@520:               <xsl:call-template name="hex2number">
sascha@520:                  <xsl:with-param
sascha@520:                       name="hex"
sascha@520:                       select="substring($hex, 1, string-length($hex)-1)"/>
sascha@520:               </xsl:call-template>
sascha@520:             </xsl:variable>
sascha@520:             <xsl:value-of select="number($last) + 16*$rest"/>
sascha@520:         </xsl:otherwise>
sascha@520:     </xsl:choose>
sascha@520:   </xsl:template>
sascha@516: 
sascha@520:   <xsl:template match="/ranges/range">
sascha@520:     <symbol>
sascha@520:       <lowervalue><xsl:value-of select="@index"/></lowervalue>
sascha@520:       <uppervalue><xsl:value-of select="@index"/></uppervalue>
sascha@520:       <label><xsl:value-of select="@description"/></label>
sascha@520:       <pointsymbol>hard:circle</pointsymbol>
sascha@520:       <pointsize>2</pointsize>
sascha@520:       <pointsizeunits>pixels</pointsizeunits>
sascha@520:       <rotationclassificationfieldname/>
sascha@520:       <scaleclassificationfieldname/>
sascha@520:       <symbolfieldname/>
sascha@520:       <outlinecolor red="0" blue="0" green="0"/>
sascha@520:       <outlinestyle>NoPen</outlinestyle>
sascha@520:       <outlinewidth>0.26</outlinewidth>
sascha@520:       <xsl:variable name="rgb">
sascha@520:         <xsl:call-template name="hex2number">
sascha@520:           <xsl:with-param name="hex" select="substring(@rgb, 2)"/>
sascha@520:         </xsl:call-template>
sascha@520:       </xsl:variable>
sascha@520:       <xsl:variable name="red" select="floor(($rgb div (256*256)) mod 256)"/>
sascha@520:       <xsl:variable name="green" select="floor(($rgb div 256) mod 256)"/>
sascha@520:       <xsl:variable name="blue" select="floor($rgb mod 256)"/>
sascha@520:       <fillcolor red="{$red}" blue="{$blue}" green="{$green}"/>
sascha@520:       <fillpattern>SolidPattern</fillpattern>
sascha@520:       <texturepath null="1"/>
sascha@520:     </symbol>
sascha@520:   </xsl:template>
sascha@520:   <xsl:template match="/">
sascha@520:     <qgis version="1.4.0-Enceladus" minimumScale="1" maximumScale="1e+08" minLabelScale="1" maxLabelScale="1e+08" hasScaleBasedVisibilityFlag="0" scaleBasedLabelVisibilityFlag="0">
sascha@520:       <transparencyLevelInt>255</transparencyLevelInt>
sascha@520:       <classificationattribute>CLASS</classificationattribute>
sascha@520:       <symbol>
sascha@520:         <lowervalue null="1"/>
sascha@520:         <uppervalue null="1"/>
sascha@520:         <label>Andere</label>
sascha@520:         <pointsymbol>hard:circle</pointsymbol>
sascha@520:         <pointsize>2</pointsize>
sascha@520:         <pointsizeunits>pixels</pointsizeunits>
sascha@520:         <rotationclassificationfieldname/>
sascha@520:         <scaleclassificationfieldname/>
sascha@520:         <symbolfieldname/>
sascha@520:         <outlinecolor red="0" blue="0" green="0"/>
sascha@520:         <outlinestyle>DashDotDotLine</outlinestyle>
sascha@520:         <outlinewidth>0.26</outlinewidth>
sascha@520:         <fillcolor red="59" blue="81" green="179"/>
sascha@520:         <fillpattern>SolidPattern</fillpattern>
sascha@520:         <texturepath null="1"/>
sascha@520:       </symbol>
sascha@520:       <uniquevalue>
sascha@520:         <classificationfield>CLASS</classificationfield>
sascha@520:         <xsl:apply-templates/>
sascha@520:       </uniquevalue>
sascha@520:       <edittypes>
sascha@520:         <edittype type="0" name="CLASS"/>
sascha@520:         <edittype type="0" name="DATE"/>
sascha@520:         <edittype type="0" name="LAYER"/>
sascha@520:         <edittype type="0" name="PARAMETER"/>
sascha@520:       </edittypes>
sascha@520:       <editform/>
sascha@520:       <editforminit/>
sascha@520:       <displayfield>PARAMETER</displayfield>
sascha@520:       <label>0</label>
sascha@520:       <attributeactions/>
sascha@520:       <labelattributes>
sascha@520:         <label fieldname="" text="Beschriftung"/>
sascha@520:         <family fieldname="" name="Sans Serif"/>
sascha@520:         <size fieldname="" units="pt" value="12"/>
sascha@520:         <bold fieldname="" on="0"/>
sascha@520:         <italic fieldname="" on="0"/>
sascha@520:         <underline fieldname="" on="0"/>
sascha@520:         <color fieldname="" red="0" blue="0" green="0"/>
sascha@520:         <x fieldname=""/>
sascha@520:         <y fieldname=""/>
sascha@520:         <offset x="0" y="0" units="pt" yfieldname="" xfieldname=""/>
sascha@520:         <angle fieldname="" value="0" auto="0"/>
sascha@520:         <alignment fieldname="" value="center"/>
sascha@520:         <buffercolor fieldname="" red="255" blue="255" green="255"/>
sascha@520:         <buffersize fieldname="" units="pt" value="1"/>
sascha@520:         <bufferenabled fieldname="" on=""/>
sascha@520:         <multilineenabled fieldname="" on=""/>
sascha@520:       </labelattributes>
sascha@520:     </qgis>
sascha@520:   </xsl:template>
sascha@520:   <xsl:template match="text()"/>
sascha@516: </xsl:stylesheet>