[Gdal-dev] [OGR] Parsing GML using XSLT

Kralidis,Tom [Burlington] Tom.Kralidis at ec.gc.ca
Wed May 23 08:21:54 EDT 2007


> Hi list,
> 
> I guess I'm missing something but I haven't been able to 
> successfully parse OGR's GML with XSLT.
> 
> Sample OGR/GML file:
> 
> <?xml version="1.0" encoding="utf-8" ?>
> <ogr:FeatureCollection
>      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>      xsi:schemaLocation="http://ogr.maptools.org/lightnings.xsd"
>      xmlns:ogr="http://ogr.maptools.org/"
>      xmlns:gml="http://www.opengis.net/gml">
>   <gml:boundedBy>
>     <gml:Box>
>       
> <gml:coord><gml:X>366874</gml:X><gml:Y>2130603</gml:Y></gml:coord>
>       
> <gml:coord><gml:X>387709</gml:X><gml:Y>2166975</gml:Y></gml:coord>
>     </gml:Box>
>   </gml:boundedBy>
>   <gml:featureMember>
>     <ogr:lightning fid="F0">
>       <ogr:geometryProperty><gml:Point><gml:coordinates>371000,2
> 149000</gml:coordinates></gml:Point></ogr:geometryProperty>
>       <ogr:rowid>42</ogr:rowid>
>       <ogr:date>2007/01/21 01:16:45</ogr:date>
>       <ogr:nbstrokes>16</ogr:nbstrokes>
>       <ogr:amplitude>-1337</ogr:amplitude>
>     </ogr:lightning>
>

The XML document above is not well formed.  You need to close the
gml:featureMember and ogr:FeatureCollection tags.  Furthermore, the root
xsi:schemaLocation should be an attribute with two (space separated)
values: the namespace, and the location (relative of URL) of the XML
Schema document.

The second issue won't prevent you from applying an XSLT transformation,
though.
 
> Sample XSL file:
> 
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
>         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>         xmlns:gml="http://www.opengis.net/gml"
>         xmlns:ogr="http://gdal.velocet.ca/ogr"
>         xmlns:xs="http://www.w3.org/2001/XMLSchema">
> 
> <xsl:output method="text" />
> 
> <xsl:template match="ogr:lightning">
>   <xsl:value-of select="@fid" />
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> It seems to be related with the ogr namespace since the gml 
> namespace doesn't cause any problem. Any hints ?

The ogr namespace defined in the GML document and the XML Schema differ;
they must be identical.

If I apply these changes to the above documents and test with something
like xsltproc, things work as expected.

Hope this helps.

..Tom







More information about the Gdal-dev mailing list