xsl-list
[Top] [All Lists]

RE: GML to svg

2004-05-21 17:08:59
Hi,

        I suggest you do the transformation by the following steps.

        1. create variable "viewBoxValue" to hold the value for "viewBox" 
attribute
of svg
                <xsl:variable name="viewBoxValue">
                        <xsl:value-of 
select="getBox(*/gml:boundedBy/gml:Box/gml:coordinates)"/>
                </xsl:variable>

        2. create main template such as follows,

        <xsl:template match="/">
                <xsl:element name="svg">
                        <xsl:attribute name="viewBox">
                                <xsl:value-of select="$viewBoxValue"/>
                        </xsl:attribute>
                        <!-- apply template to each GML geometry property -->
                        <xsl:apply-templates 
select="//pre1:cityMember/gml:centerLineOf" />
                </xsl:element>
        </xsl:template>

        3. create a template that transforms the GML centerLineOf property to 
SVG
path element.

                <xsl:template match="pre1:cityMember/gml:centerLineOf">
                        <xsl:element name="path">
                                <xsl:attribute
name="style">stroke-width:fill:none;stroke:rgb(69,34,118);</xsl:attribute>

                                <xsl:attribute name='d'>
                                        <xsl:value-of 
select="convertCoordToPathCoord(./gml:coordinates)" />
                                </xsl:attribute>
                        </xsl:element>
                </xsl:template>

                The function convertToPathCoord(./gml:coordinates) converts the 
GML
coordiates contained in the gml:coordinates element into SVG path
coordinates, for example, given the GML coordinates "0 50,70 60,100 50", it
should return "M0,50 L70,60 L100, 50"

                You can implement this function and getBox() with Java or use 
XSLT 2.0
tokeniz function.

                Pleas also note you should declare the related namespaces in 
XSLT root
element as follows,

                <xsl:transform xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
                        xmlns:xlink='http://www.w3.org/1999/xlink'
                        xmlns:pre1='http://www.opengis.net/examples'
                        xmlns:gml='http://www.opengis.net/gml'>


                Hope this helps.

                Lisa


-----Original Message-----
From: sarra hamdi [mailto:hacker249(_at_)lycos(_dot_)com]
Sent: Friday, May 21, 2004 8:36 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] GML to svg



Hello,
I have a valid GML file descriped follow, it was validated by xmlspy. I want
to transform it to SVG format using xslt but I m newbie in xsl language.
follow the xsl file that I writed but it cant give me a the same result
described in the output svg file.
from this can any one see this files to help me to write the xslt file
correspind to my gml file to give me the same result of the svg file
described in follow.
thanks advanced.

------------------------------------------------
the gml file
------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!-- File: cambridge.xml -->
<CityModel xmlns="http://www.opengis.net/examples";
          xmlns:gml="http://www.opengis.net/gml";
          xmlns:xlink="http://www.w3.org/1999/xlink";
           xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance";
          xsi:schemaLocation="http://www.opengis.net/examples
/u/pkg/gml4j/test/schemas/City.xsd">

  <gml:name>Cambridge</gml:name>
  <gml:boundedBy>
    <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326";>
      <gml:coordinates>0.0 0.0,100.0 100.0</gml:coordinates>
    </gml:Box>
  </gml:boundedBy>

<cityMember>
    <River>
      <gml:description>The river that runs through
Cambridge.</gml:description>
     <gml:name>Cam</gml:name>
      <gml:centerLineOf>
        <gml:LineString
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326";>
         <gml:coordinates>0 50,70 60,100 50</gml:coordinates>
        </gml:LineString>
      </gml:centerLineOf>
    </River>
  </cityMember>

  <cityMember>
    <Road>
      <gml:name>M11</gml:name>
       <linearGeometry>
          <gml:LineString
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326";>
           <gml:coordinates>0 5.0,20.6 10.7,80.5 60.9</gml:coordinates>
          </gml:LineString>
        </linearGeometry>
      <classification>motorway</classification>
      <number>11</number>
    </Road>
  </cityMember>

  <cityMember xlink:type="simple" xlink:title="Trinity Lane"
    xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239";
    gml:remoteSchema="city.xsd#xpointer(//complexType[(_at_)name='RoadType'])"/>
  <cityMember>
    <Mountain>
      <gml:description>World's highest mountain is in
Nepal!</gml:description>
      <gml:name>Everest</gml:name>
      <elevation>8850</elevation>
    </Mountain>
  </cityMember>
  <dateCreated>2000-11</dateCreated>
</CityModel>


------------------------------------------------
the xsl file
------------------------------------------------<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet SYSTEM "C:\Documents and
Settings\ines\Bureau\exemple3\Untitled2.dtd">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xlink="http://www.w3.org/TR/xlink";
xmlns:gml="http://www.opengis.net/gml";
xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
xmlns:mur="murmur" extension-element-prefixes="mur">
        <xsl:output method="xml"
doctype-system="D:\mesrecherchesmastere\svg\DTD\svg10.dtd"
doctype-public="-//W3C//DTD SVG 20000303 Stylable//EN"/>
        <xsl:variable name="boxCoord" select="//gml:Box/gml:coordinates/."/>
             <xsl:template
match="//gml:centerLineOf/gml:LineString/gml:coordinates">
                <xsl:variable name="clist" select="."/>
                <xsl:variable name="tclist" select="normalize-space($clist)"/>
                <xsl:template match="/">
                        <xsl:variable name="boxCoord"></xsl:variable>
                        <xsl:template match="/">
                <svg xml:space="preserve" viewBox="{$boxCoord}">
                        <xsl:apply-templates/>
                </svg>
        </xsl:template>
        </xsl:template>
        </xsl:template>
</xsl:stylesheet>
--------------------------------------------------
the wanted output svg file
-----------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg SYSTEM "C:\Documents and
Settings\Administrateur\Bureau\Untitled2.dtd">
<svg width="50cm" height="20cm" viewBox="0 0 800 40"
xmlns:gml="http://www.opengis.net/gml";
xmlns:xlink="http://www.w3.org/TR/xlink"; xml:space="preserve"
xmlns="http://www.w3.org/2000/svg";>

        <g transform="rotate(-100)">
                <g stroke="green">
                        <line x1="50" y1="0" x2="60" y2="70" stroke-width="2"/>
                        <line x1="60" y1="70" x2="50" y2="100" 
stroke-width="2"/>
                </g>
                <text x="0" y="0" font-size="10" font-family="Verdana" 
fill="blue">River
</text>
                <g stroke="red">
                        <g transform="rotate(20)">
                                                </g>
                        <line x1="5.0" y1="0.0" x2="10.7" y2="20.6" 
stroke-width="5"/>
                        <line x1="10.7" y1="20.6" x2="60.9" y2="80.5" 
stroke-width="5"/>
                        <line x1="60.9" y1="80.5" x2="100" y2="90" 
stroke-width="5"/>
                </g>
        </g>
        <text x="0" y="2" font-size="10" font-family="Verdana" fill="blue">
Road
</text>
        <text x="0" y="-70" font-size="10" font-family="Verdana" fill="blue">
River
</text>
        <path style="stroke:$colorc;fill:$remplir" d=""/>
        <path style="stroke:$colorc;fill:$remplir" d=""/>





____________________________________________________________
Find what you are looking for with the Lycos Yellow Pages
http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp
?SRC=lycos10

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





<Prev in Thread] Current Thread [Next in Thread>