|
Hi,
attached is an example of xslt for gml2svg
conversion. I have the whole working example with gml data, schemas etc, but I
didn't want to sent a 1 Meg attachment to the list. If anyone wants the rest of
the files I will be glad to send it out.
Cheers
Milan
=========================================
Milan Trninic Senior Software Engineer tel: 1 604 484-2764, 484-2750 [EMAIL PROTECTED] Galdos Systems Inc� http://www.galdosinc.com ========================================= ===============
|
<?xml version="1.0" encoding="utf-8" ?> <!-- ==================================================================================== XSLT Transformation Stylesheet Example Transforms GML2.1.1 to SVG Created by FreeStyler (TM) Suite Copyright 1999-2003 Galdos Systems Inc. http://www.galdosinc.com ======================================================================================= --> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:saxon="http://icl.com/saxon" xmlns:Extfun="/org.opengis.gml.StyleExt" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.opengis.net/gml" xmlns:gml.tm="http://www.opengis.net/gml/temporal" xmlns:wfs="http://www.galdos.com/wfs" xmlns:exp="http://www.opengis.net/examples" > <xsl:output indent="yes"/> <xsl:param name="CONVTYPE">pixel</xsl:param> <xsl:param name="WIDTH">500</xsl:param> <xsl:param name="HEIGHT">400</xsl:param> <xsl:variable name='sumY'> <xsl:apply-templates select='exp:FeatureCollection/gml:boundedBy/gml:Box/gml:coordinates' mode='sumY'/> </xsl:variable> <xsl:variable name='scaleX'> <xsl:apply-templates select='exp:FeatureCollection/gml:boundedBy/gml:Box/gml:coordinates' mode='scaleX'/> </xsl:variable> <xsl:variable name='scaleY'> <xsl:apply-templates select='exp:FeatureCollection/gml:boundedBy/gml:Box/gml:coordinates' mode='scaleY'/> </xsl:variable> <xsl:variable name='x1'> <xsl:apply-templates select='exp:FeatureCollection/gml:boundedBy/gml:Box/gml:coordinates' mode='x1'/> </xsl:variable> <xsl:variable name='y1'> <xsl:apply-templates select='exp:FeatureCollection/gml:boundedBy/gml:Box/gml:coordinates' mode='y1'/> </xsl:variable> <xsl:variable name="minus">-1</xsl:variable> <xsl:variable name="one">1</xsl:variable> <xsl:variable name="inverseScale"><xsl:value-of select="$one div $scaleX"/></xsl:variable> <xsl:template match="/"> <xsl:element name="svg"> <xsl:attribute name="width"><xsl:value-of select="$WIDTH"/></xsl:attribute> <xsl:attribute name="height"><xsl:value-of select="$HEIGHT"/></xsl:attribute> <xsl:element name="defs"> <xsl:element name='g'> <xsl:attribute name='id'>Lib1_9</xsl:attribute> <xsl:if test="$CONVTYPE='pixel'"> <xsl:attribute name='transform'>scale(0.25)</xsl:attribute> </xsl:if> <xsl:if test="$CONVTYPE='user'"> <xsl:attribute name='transform'>scale(<xsl:value-of select='$inverseScale'/>) scale(0.25) matrix(1 0 0 -1 0 70)</xsl:attribute> </xsl:if> <xsl:element name='path'> <xsl:attribute name='style'>fill-rule:nonzero;fill:#EBF322;stroke:#000000;stroke-miterlimit:4;</xsl:attribute> <xsl:attribute name='d'>M68.262,74.51H0.5V37.255h67.762V74.51z</xsl:attribute> </xsl:element> <xsl:element name='path'> <xsl:attribute name='style'>fill-rule:nonzero;fill:#EBF322;stroke:#000000;stroke-miterlimit:4;</xsl:attribute> <xsl:attribute name='d'>M13.793,17.647h41.176</xsl:attribute> </xsl:element> <xsl:element name='path'> <xsl:attribute name='style'>fill-rule:nonzero;fill:#EBF322;stroke:#000000;stroke-miterlimit:4;</xsl:attribute> <xsl:attribute name='d'>M31.44,0v35.294</xsl:attribute> </xsl:element> </xsl:element> </xsl:element> <xsl:if test="$CONVTYPE = 'pixel'"> <xsl:apply-templates select="//exp:Ocean/gml:extentOf" mode='Area' /> <xsl:apply-templates select="//exp:Church/gml:location" mode='Point' /> <xsl:apply-templates select="//exp:RL1U/gml:centerLineOf" mode='Line' /> </xsl:if> <xsl:if test="$CONVTYPE = 'user'"> <xsl:element name="g"> <xsl:attribute name="transform">scale(<xsl:value-of select="$scaleX"/>,<xsl:value-of select="$scaleY"/>) translate(<xsl:value-of select="$minus*$x1"/>,<xsl:value-of select="$minus*$y1"/>) matrix(1 0 0 -1 0 <xsl:apply-templates select="/gml:boundedBy/gml:Box/gml:coordinates" mode="sumY"/>)</xsl:attribute> <xsl:apply-templates select="//exp:Ocean/gml:extentOf" mode='Area' /> <xsl:apply-templates select="//exp:Church/gml:location" mode='Point' /> <xsl:apply-templates select="//exp:RL1U/gml:centerLineOf" mode='Line' /> </xsl:element> </xsl:if> </xsl:element> </xsl:template> <xsl:template match="gml:boundedBy/gml:Box/gml:coordinates" mode="scaleX"> <xsl:value-of select="Extfun:getScaleX(string($WIDTH),string(text()),string(@decimal),string(@cs),string(@ts))"/> </xsl:template> <xsl:template match="gml:boundedBy/gml:Box/gml:coordinates" mode="scaleY"> <xsl:value-of select="Extfun:getScaleY(string($HEIGHT),string(text()),string(@decimal),string(@cs),string(@ts))"/> </xsl:template> <xsl:template match="gml:boundedBy/gml:Box/gml:coordinates" mode="x1"> <xsl:value-of select="Extfun:getX1(string(text()),string(@decimal),string(@cs),string(@ts))"/> </xsl:template> <xsl:template match="gml:boundedBy/gml:Box/gml:coordinates" mode="y1"> <xsl:value-of select="Extfun:getY1(string(text()),string(@decimal),string(@cs),string(@ts))"/> </xsl:template> <xsl:template match="gml:boundedBy/gml:Box/gml:coordinates" mode="sumY"> <xsl:value-of select="Extfun:getSumY(string(text()),string(@decimal),string(@cs),string(@ts))"/> </xsl:template> <xsl:template match="gml:boundedBy/gml:Box/gml:coordinates" mode="inverseScale"> <xsl:value-of select="Extfun:getInverseScale(string(text()),string(@decimal),string(@cs),string(@ts))"/> </xsl:template> <xsl:template match="exp:Ocean/gml:extentOf" mode='Area' > <xsl:variable name='strokeWidth'> <xsl:value-of select='2'/> </xsl:variable> <xsl:variable name='rFill'> <xsl:value-of select='0'/> </xsl:variable> <xsl:variable name='gFill'> <xsl:value-of select='0'/> </xsl:variable> <xsl:variable name='bFill'> <xsl:value-of select='255'/> </xsl:variable> <xsl:variable name='rStroke'> <xsl:value-of select='0'/> </xsl:variable> <xsl:variable name='gStroke'> <xsl:value-of select='0'/> </xsl:variable> <xsl:variable name='bStroke'> <xsl:value-of select='255'/> </xsl:variable> <xsl:variable name='strokeDasharray'>6 2 2 2 2 2</xsl:variable> <xsl:variable name="dash0">6</xsl:variable> <xsl:variable name="dash1">2</xsl:variable> <xsl:variable name="dash2">2</xsl:variable> <xsl:variable name="dash3">2</xsl:variable> <xsl:variable name="dash4">2</xsl:variable> <xsl:variable name="dash5">2</xsl:variable> <xsl:variable name='idVar'> <xsl:call-template name='getAnc'> <xsl:with-param name='featureName' select="'exp:Ocean'"/> </xsl:call-template> </xsl:variable> <xsl:element name="path"> <xsl:if test="$CONVTYPE='pixel'"> <xsl:attribute name="style">stroke-width:<xsl:value-of select='$strokeWidth'/>;fill:rgb(<xsl:value-of select='$rFill'/>,<xsl:value-of select='$gFill'/>,<xsl:value-of select='$bFill'/>);stroke:rgb(<xsl:value-of select='$rStroke'/>,<xsl:value-of select='$gStroke'/>,<xsl:value-of select='$bStroke'/>);fill-rule:evenodd;</xsl:attribute> </xsl:if> <xsl:if test="$CONVTYPE='user'"> <xsl:attribute name="style">stroke-width:<xsl:value-of select="$strokeWidth*$inverseScale"/>;fill:rgb(<xsl:value-of select='$rFill'/>,<xsl:value-of select='$gFill'/>,<xsl:value-of select='$bFill'/>);stroke:rgb(<xsl:value-of select='$rStroke'/>,<xsl:value-of select='$gStroke'/>,<xsl:value-of select='$bStroke'/>);</xsl:attribute> </xsl:if> <xsl:attribute name='id'><xsl:value-of select='$idVar'/></xsl:attribute> <xsl:attribute name="d"> <xsl:apply-templates select=".//gml:coordinates" mode="Path" /> </xsl:attribute> </xsl:element> </xsl:template> <xsl:template match="exp:Church/gml:location" mode='Point' > <xsl:variable name='idVar'> <xsl:call-template name='getAnc'> <xsl:with-param name='featureName' select="'exp:Church'"/> </xsl:call-template> </xsl:variable> <xsl:variable name='x'><xsl:apply-templates select='.//gml:coordinates' mode='PointX'/></xsl:variable> <xsl:variable name='y'><xsl:apply-templates select='.//gml:coordinates' mode='PointY'/></xsl:variable> <xsl:variable name='scaleValue'> <xsl:value-of select='1'/> </xsl:variable> <xsl:element name="use"> <xsl:attribute name='id'><xsl:value-of select='$idVar'/></xsl:attribute> <xsl:attribute name="xlink:href">#Lib1_9</xsl:attribute> <xsl:attribute name='transform'>translate(<xsl:value-of select='$x'/>,<xsl:value-of select='$y'/>) scale(<xsl:value-of select='$scaleValue'/>) </xsl:attribute> </xsl:element> </xsl:template> <xsl:template match="exp:RL1U/gml:centerLineOf" mode='Line' > <xsl:variable name='strokeWidth'> <xsl:value-of select='1'/> </xsl:variable> <xsl:variable name='rStroke'> <xsl:value-of select='255'/> </xsl:variable> <xsl:variable name='gStroke'> <xsl:value-of select='0'/> </xsl:variable> <xsl:variable name='bStroke'> <xsl:value-of select='0'/> </xsl:variable> <xsl:variable name='idVar'> <xsl:call-template name='getAnc'> <xsl:with-param name='featureName' select="'exp:RL1U'"/> </xsl:call-template> </xsl:variable> <xsl:element name="path"> <xsl:if test="$CONVTYPE='pixel'"> <xsl:attribute name="style">stroke-width:<xsl:value-of select='$strokeWidth'/>;fill:none;stroke:rgb(<xsl:value-of select='$rStroke'/>,<xsl:value-of select='$gStroke'/>,<xsl:value-of select='$bStroke'/>);</xsl:attribute> </xsl:if> <xsl:if test="$CONVTYPE='user'"> <xsl:attribute name="style">stroke-width:<xsl:value-of select="$strokeWidth*$inverseScale"/>;fill:none;stroke:rgb(<xsl:value-of select='$rStroke'/>,<xsl:value-of select='$gStroke'/>,<xsl:value-of select='$bStroke'/>);</xsl:attribute> </xsl:if> <xsl:attribute name='id'><xsl:value-of select='$idVar'/></xsl:attribute> <xsl:attribute name="d"> <xsl:apply-templates select=".//gml:coordinates" mode="Path" /> </xsl:attribute> </xsl:element> </xsl:template> <xsl:template match="gml:coordinates" mode="PointX"> <xsl:if test="$CONVTYPE = 'pixel'"> <xsl:value-of select="Extfun:getPointX(string($scaleX),string($x1),string(text()),string(@decimal),string(@cs))" /> </xsl:if> <xsl:if test="$CONVTYPE = 'user'"> <xsl:value-of select="Extfun:getPointX(string(text()),string(@decimal),string(@cs))" /> </xsl:if> </xsl:template> <xsl:template match="gml:coordinates" mode="PointY"> <xsl:if test="$CONVTYPE = 'pixel'"> <xsl:value-of select="Extfun:getPointY(string($sumY),string($scaleY),string($y1),string(text()),string(@decimal),string(@cs))" /> </xsl:if> <xsl:if test="$CONVTYPE = 'user'"> <xsl:value-of select="Extfun:getPointY(string(text()),string(@decimal),string(@cs))" /> </xsl:if> </xsl:template> <xsl:template match="gml:coordinates" mode="Path"> <xsl:if test="$CONVTYPE = 'pixel'"> <xsl:value-of select="Extfun:convertCoordinatesToPath(string($sumY),string($scaleX),string($scaleY),string($x1),string($y1),string(text()),string(@decimal),string(@cs),string(@ts))" /> </xsl:if> <xsl:if test="$CONVTYPE = 'user'"> <xsl:value-of select="Extfun:convertCoordinatesToPath(string(text()),string(@decimal),string(@cs),string(@ts))"/> </xsl:if> </xsl:template> <xsl:template name='getAnc'> <xsl:param name='featureName' /> <xsl:choose> <xsl:when test='name(.) = $featureName'> <xsl:value-of select='./@ID'/> </xsl:when> <xsl:otherwise> <xsl:for-each select='..'> <xsl:call-template name='getAnc'> <xsl:with-param name='featureName' select='$featureName'/> </xsl:call-template> </xsl:for-each> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:transform>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
