source: trunk/doc/xsl/postgis_gardentest.sql.xsl @ 6346

Last change on this file since 6346 was 6346, checked in by robe, 6 years ago

remove collection of geometries into crasher group to prevent testing until we revisit #700

  • Property svn:keywords set to Author Date Id Revision
File size: 41.2 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:pgis="http://postgis.refractions.net/pgis">
3<!-- ********************************************************************
4 * $Id: postgis_gardentest.sql.xsl 6346 2010-12-13 13:14:51Z robe $
5 ********************************************************************
6         Copyright 2008-2010, Regina Obe
7         License: BSD
8         Purpose: This is an xsl transform that generates an sql test script from xml docs to test all the functions we have documented
9                        using a garden variety of geometries.  Its intent is to flag major crashes.
10         ******************************************************************** -->
11        <xsl:output method="text" />
12        <xsl:variable name='testversion'>2.0.0</xsl:variable>
13        <xsl:variable name='fnexclude14'>AddGeometryColumn DropGeometryColumn DropGeometryTable</xsl:variable>
14        <xsl:variable name='fnexclude'>AddGeometryColumn DropGeometryColumn DropGeometryTable Populate_Geometry_Columns ST_AddPoint ST_MinimumBoundingCircle</xsl:variable>
15        <!--This is just a place holder to state functions not supported in 1.3 or tested separately -->
16
17        <xsl:variable name='var_srid'>3395</xsl:variable>
18        <xsl:variable name='var_position'>1</xsl:variable>
19        <xsl:variable name='var_integer1'>3</xsl:variable>
20        <xsl:variable name='var_integer2'>5</xsl:variable>
21        <xsl:variable name='var_float1'>0.5</xsl:variable>
22        <xsl:variable name='var_float2'>0.75</xsl:variable>
23        <xsl:variable name='var_distance'>100</xsl:variable>
24        <xsl:variable name='var_version1'>1</xsl:variable>
25        <xsl:variable name='var_version2'>2</xsl:variable>
26        <xsl:variable name='var_gj_version'>1</xsl:variable> <!-- GeoJSON version -->
27        <xsl:variable name='var_NDRXDR'>XDR</xsl:variable>
28        <xsl:variable name='var_text'>'monkey'</xsl:variable>
29        <xsl:variable name='var_varchar'>'test'</xsl:variable>
30        <xsl:variable name='var_spheroid'>'SPHEROID["GRS_1980",6378137,298.257222101]'</xsl:variable>
31        <xsl:variable name='var_matrix'>'FF1FF0102'</xsl:variable>
32        <xsl:variable name='var_boolean'>false</xsl:variable>
33        <xsl:variable name='var_logtable'>postgis_garden_log</xsl:variable>
34        <xsl:variable name='var_logupdatesql'>UPDATE <xsl:value-of select="$var_logtable" /> SET log_end = clock_timestamp()
35                FROM (SELECT logid FROM <xsl:value-of select="$var_logtable" /> ORDER BY logid DESC limit 1) As foo
36                WHERE <xsl:value-of select="$var_logtable" />.logid = foo.logid  AND <xsl:value-of select="$var_logtable" />.log_end IS NULL;</xsl:variable>
37               
38        <!-- for queries that result data, we first log the sql in our log table and then use query_to_xml to output it as xml for easy storage
39            with this approach our run statement is always exactly the same -->
40        <xsl:variable name='var_logresultsasxml'>INSERT INTO <xsl:value-of select="$var_logtable" />_output(logid, log_output)
41                                SELECT logid, query_to_xml(log_sql, false,false,'') As log_output
42                                    FROM <xsl:value-of select="$var_logtable" /> ORDER BY logid DESC LIMIT 1;</xsl:variable>
43        <pgis:gardens>
44                <pgis:gset ID='POINT' GeometryType='POINT'>(SELECT ST_SetSRID(ST_Point(i,j),4326) As the_geom
45                FROM (SELECT a*1.11111111 FROM generate_series(-10,50,10) As a) As i(i)
46                        CROSS JOIN generate_series(40,70, 15) j
47                        ORDER BY i,j
48                        )</pgis:gset>
49                <pgis:gset ID='LINESTRING' GeometryType='LINESTRING'>(SELECT ST_MakeLine(ST_SetSRID(ST_Point(i,j),4326),ST_SetSRID(ST_Point(j,i),4326))  As the_geom
50                FROM (SELECT a*1.11111111 FROM generate_series(-10,50,10) As a) As i(i)
51                        CROSS JOIN generate_series(40,70, 15) As j
52                        WHERE NOT(i = j)
53                        ORDER BY i, i*j)</pgis:gset>
54                <pgis:gset ID='POLYGON' GeometryType='POLYGON'>(SELECT ST_Buffer(ST_SetSRID(ST_Point(i,j),4326), j*0.05)  As the_geom
55                FROM (SELECT a*1.11111111 FROM generate_series(-10,50,10) As a) As i(i)
56                        CROSS JOIN generate_series(40,70, 20) As j
57                        ORDER BY i, i*j, j)</pgis:gset>
58                <pgis:gset ID='POINTM' GeometryType='POINTM'>(SELECT ST_SetSRID(ST_MakePointM(i,j,m),4326) As the_geom
59                FROM generate_series(-10,50,10) As i
60                        CROSS JOIN generate_series(50,70, 20) AS j
61                        CROSS JOIN generate_series(1,2) As m
62                        ORDER BY i, j, i*j*m)</pgis:gset>
63                <pgis:gset ID='LINESTRINGM' GeometryType='LINESTRINGM'>(SELECT ST_MakeLine(ST_SetSRID(ST_MakePointM(i,j,m),4326),ST_SetSRID(ST_MakePointM(j,i,m),4326))  As the_geom
64                FROM generate_series(-10,50,10) As i
65                        CROSS JOIN generate_series(50,70, 20) As j
66                        CROSS JOIN generate_series(1,2) As m
67                        WHERE NOT(i = j)
68                        ORDER BY i, j, m, i*j*m)</pgis:gset>
69<!--            <pgis:gset ID='PolygonMSet' GeometryType='POLYGONM'>(SELECT ST_MakePolygon(ST_AddPoint(ST_AddPoint(ST_MakeLine(ST_SetSRID(ST_MakePointM(i+m,j,m),4326),ST_SetSRID(ST_MakePointM(j+m,i-m,m),4326)),ST_SetSRID(ST_MakePointM(i,j,m),4326)),ST_SetSRID(ST_MakePointM(i+m,j,m),4326)))  As the_geom
70                FROM generate_series(-10,50,20) As i
71                        CROSS JOIN generate_series(50,70, 20) As j
72                        CROSS JOIN generate_series(1,2) As m
73                        ORDER BY i, j, m, i*j*m
74                        )</pgis:gset>-->
75                <pgis:gset ID='POLYGONM' GeometryType='POLYGONM'>(SELECT geom  As the_geom
76FROM (VALUES ( ST_GeomFromEWKT('SRID=4326;POLYGONM((-71.1319 42.2503 1,-71.132 42.2502 3,-71.1323 42.2504 -2,-71.1322 42.2505 1,-71.1319 42.2503 0))') ),
77        ( ST_GeomFromEWKT('SRID=4326;POLYGONM((-71.1319 42.2512 0,-71.1318 42.2511 20,-71.1317 42.2511 -20,-71.1317 42.251 5,-71.1317 42.2509 4,-71.132 42.2511 6,-71.1319 42.2512 30))') )
78                )       As g(geom))</pgis:gset>
79               
80                <pgis:gset ID='POINTZ' GeometryType='POINTZ'>(SELECT ST_SetSRID(ST_MakePoint(i,j,k),4326) As the_geom
81                FROM generate_series(-10,50,20) As i
82                        CROSS JOIN generate_series(40,70, 20) j
83                        CROSS JOIN generate_series(1,2) k
84                        ORDER BY i,i*j, j*k, i + j + k)</pgis:gset>
85                <pgis:gset ID='LINESTRINGZ' GeometryType='LINESTRINGZ'>(SELECT ST_SetSRID(ST_MakeLine(ST_MakePoint(i,j,k), ST_MakePoint(i+k,j+k,k)),4326) As the_geom
86                FROM generate_series(-10,50,20) As i
87                        CROSS JOIN generate_series(40,70, 20) j
88                        CROSS JOIN generate_series(1,2) k
89                        ORDER BY i, j, i+j+k, k, i*j*k)</pgis:gset>
90<!--            <pgis:gset ID='PolygonSet3D' GeometryType='POLYGONZ'>(SELECT ST_SetSRID(ST_MakePolygon(ST_AddPoint(ST_AddPoint(ST_MakeLine(ST_MakePoint(i+m,j,m),ST_MakePoint(j+m,i-m,m)),ST_MakePoint(i,j,m)),ST_MakePointM(i+m,j,m))),4326)  As the_geom
91                FROM generate_series(-10,50,20) As i
92                        CROSS JOIN generate_series(50,70, 20) As j
93                        CROSS JOIN generate_series(1,2) As m
94                        ORDER BY i, j, i+j+m, m, i*j*m)</pgis:gset>--> 
95                <pgis:gset ID='POLYGONZ' GeometryType='POLYGONZ'>(SELECT geom  As the_geom
96FROM (VALUES ( ST_GeomFromEWKT('SRID=4326;POLYGON((-71.0771 42.3866 1,-71.0767 42.3872 1,-71.0767 42.3863 1,-71.0771 42.3866 1))') ),
97        ( ST_GeomFromEWKT('SRID=4326;POLYGON((-71.0775 42.386 2,-71.0773 42.3863 1.75,-71.0773 42.3859 1.75,-71.0775 42.386 2))') )
98                )       As g(geom))</pgis:gset>
99               
100                <pgis:gset ID='POLYGONZM' GeometryType='POLYGONZM'>(SELECT geom  As the_geom
101FROM (VALUES ( ST_GeomFromEWKT('SRID=4326;POLYGON((-71.0771 42.3866 1 2,-71.0767 42.3872 1 2.3,-71.0767 42.3863 1 2.3,-71.0771 42.3866 1 2))') ),
102        ( ST_GeomFromEWKT('SRID=4326;POLYGON((-71.0775 42.386 2 1.5,-71.0773 42.3863 1.75 1.5,-71.0773 42.3859 1.75 1.5,-71.0775 42.386 2 1.5))') )
103                )       As g(geom))</pgis:gset>
104                       
105                <pgis:gset ID='POLYHEDRALSURFACE' GeometryType='POLYHEDRALSURFACE'>(SELECT ST_Translate(the_geom,-72.2, 41.755) As the_geom
106                FROM (VALUES ( ST_GeomFromEWKT(
107'SRID=4326;PolyhedralSurface(
108((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)), 
109((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),  ((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)), 
110((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)),  ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1))
111)') ) ,
112( ST_GeomFromEWKT(
113'SRID=4326;PolyhedralSurface(
114((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)), 
115((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)) )') ) )
116As foo(the_geom)  ) </pgis:gset>
117
118                <pgis:gset ID='TRIANGLE' GeometryType='TRIANGLE'>(SELECT ST_GeomFromEWKT(
119'SRID=4326;TRIANGLE ((
120                -71.0821 42.3036,
121                -71.0821 42.3936,
122                -71.0901 42.3036,
123                -71.0821 42.3036
124            ))') As the_geom) </pgis:gset>
125           
126                <pgis:gset ID='TIN' GeometryType='TIN'>(SELECT ST_GeomFromEWKT(
127'SRID=4326;TIN (((
128                -71.0821 42.3036 0,
129               -71.0821 42.3036 1,
130                -71.0821 42.3436 0,
131                -71.0821 42.3036 0
132            )), ((
133                -71.0821 42.3036 0,
134                -71.0821 42.3436 0,
135                -71.0831 42.3436 0,
136                -71.0821 42.3036 0
137            ))
138            )') As the_geom) </pgis:gset>
139
140<!--            <pgis:gset ID='GCSet3D' GeometryType='GEOMETRYCOLLECTIONZ' SkipUnary='1'>(SELECT ST_Collect(ST_Collect(ST_SetSRID(ST_MakePoint(i,j,m),4326),ST_SetSRID(ST_MakePolygon(ST_AddPoint(ST_AddPoint(ST_MakeLine(ST_MakePoint(i+m,j,m),ST_MakePoint(j+m,i-m,m)),ST_MakePoint(i,j,m)),ST_MakePointM(i+m,j,m))),4326)))  As the_geom
141                FROM generate_series(-10,50,20) As i
142                        CROSS JOIN generate_series(50,70, 20) As j
143                        CROSS JOIN generate_series(1,2) As m
144                        )</pgis:gset>-->
145                <pgis:gset ID='GEOMETRYCOLLECTIONZ' GeometryType='GEOMETRYCOLLECTIONZ' SkipUnary='1'>(SELECT ST_Collect(geom)  As the_geom
146                FROM (VALUES ( ST_GeomFromEWKT('SRID=4326;MULTIPOLYGON(((-71.0821 42.3036 2,-71.0822 42.3036 2,-71.082 42.3038 2,-71.0819 42.3037 2,-71.0821 42.3036 2)))') ),
147        ( ST_GeomFromEWKT('SRID=4326;POLYGON((-71.1261 42.2703 1,-71.1257 42.2703 1,-71.1257 42.2701 1,-71.126 42.2701 1,-71.1261 42.2702 1,-71.1261 42.2703 1))') )
148                )       As g(geom) CROSS JOIN generate_series(1,3) As i
149                GROUP BY i
150                        )</pgis:gset>
151                       
152                <pgis:gset ID='GEOMETRYCOLLECTIONM' GeometryType='GEOMETRYCOLLECTIONM' SkipUnary='1'>(SELECT ST_Collect(geom)  As the_geom
153                FROM (VALUES ( ST_GeomFromEWKT('SRID=4326;MULTIPOLYGONM(((-71.0821 42.3036 2,-71.0822 42.3036 3,-71.082 42.3038 2,-71.0819 42.3037 2,-71.0821 42.3036 2)))') ),
154        ( ST_GeomFromEWKT('SRID=4326;POLYGONM((-71.1261 42.2703 1,-71.1257 42.2703 1,-71.1257 42.2701 2,-71.126 42.2701 1,-71.1261 42.2702 1,-71.1261 42.2703 1))') )
155                )       As g(geom) CROSS JOIN generate_series(1,3) As i
156                GROUP BY i
157                        )</pgis:gset>
158
159<!-- MULTIs start here -->
160                <pgis:gset ID='MULTIPOINT' GeometryType='MULTIPOINT'>(SELECT ST_Collect(s.the_geom) As the_geom
161                FROM (SELECT ST_SetSRID(ST_Point(i,j),4326) As the_geom
162                FROM generate_series(-10,50,15) As i
163                        CROSS JOIN generate_series(40,70, 15) j
164                        ) As s)</pgis:gset>
165
166                <pgis:gset ID='MULTILINESTRING' GeometryType='MULTILINESTRING'>(SELECT ST_Collect(s.the_geom) As the_geom
167                FROM (SELECT ST_MakeLine(ST_SetSRID(ST_Point(i,j),4326),ST_SetSRID(ST_Point(j,i),4326))  As the_geom
168                FROM generate_series(-10,50,10) As i
169                        CROSS JOIN generate_series(40,70, 15) As j
170                        WHERE NOT(i = j)) As s)</pgis:gset>
171
172                <pgis:gset ID='MULTIPOLYGON' GeometryType='MULTIPOLYGON'>(SELECT ST_Multi(ST_Union(ST_Buffer(ST_SetSRID(ST_Point(i,j),4326), j*0.05)))  As the_geom
173                FROM generate_series(-10,50,10) As i
174                        CROSS JOIN generate_series(40,70, 25) As j)</pgis:gset>
175
176                <pgis:gset ID='MULTIPOINTZ' GeometryType='MULTIPOINTZ'>(SELECT ST_Collect(ST_SetSRID(ST_MakePoint(i,j,k),4326)) As the_geom
177                FROM generate_series(-10,50,20) As i
178                        CROSS JOIN generate_series(40,70, 25) j
179                        CROSS JOIN generate_series(1,3) k
180                        )</pgis:gset>
181
182                <pgis:gset ID='MULTILINESTRINGZ' GeometryType='MULTILINESTRINGZ'>(SELECT ST_Multi(ST_Union(ST_SetSRID(ST_MakeLine(ST_MakePoint(i,j,k), ST_MakePoint(i+k,j+k,k)),4326))) As the_geom
183                FROM generate_series(-10,50,20) As i
184                        CROSS JOIN generate_series(40,70, 25) j
185                        CROSS JOIN generate_series(1,2) k
186                        )</pgis:gset>
187
188<!--            <pgis:gset ID='MultiPolySet3D' GeometryType='MULTIPOLYGONZ'>(SELECT ST_Multi(ST_Union(s.the_geom)) As the_geom
189                FROM (SELECT ST_MakePolygon(ST_AddPoint(ST_AddPoint(ST_MakeLine(ST_SetSRID(ST_MakePoint(i+m,j,m),4326),ST_SetSRID(ST_MakePoint(j+m,i-m,m),4326)),ST_SetSRID(ST_MakePoint(i,j,m),4326)),ST_SetSRID(ST_MakePoint(i+m,j,m),4326)))  As the_geom
190                FROM generate_series(-10,50,20) As i
191                        CROSS JOIN generate_series(50,70, 25) As j
192                        CROSS JOIN generate_series(1,2) As m
193                        ) As s)</pgis:gset>-->
194                <pgis:gset ID='MULTIPOLYGONZ' GeometryType='MULTIPOLYGONZ'>(SELECT geom  As the_geom
195FROM (VALUES ( ST_GeomFromEWKT('SRID=4326;MULTIPOLYGON(((-71.0821 42.3036 2,-71.0822 42.3036 2,-71.082 42.3038 2,-71.0819 42.3037 2,-71.0821 42.3036 2)))') ),
196        ( ST_GeomFromEWKT('SRID=4326;MULTIPOLYGON(((-71.1261 42.2703 1,-71.1257 42.2703 1,-71.1257 42.2701 1,-71.126 42.2701 1,-71.1261 42.2702 1,-71.1261 42.2703 1)))') )
197                )       As g(geom))</pgis:gset>
198                       
199
200                <pgis:gset ID='MULTIPOINTM' GeometryType='MULTIPOINTM'>(SELECT ST_Collect(s.the_geom) As the_geom
201                FROM (SELECT ST_SetSRID(ST_MakePointM(i - 0.0821,j + 0.3036,m),4326) As the_geom
202                FROM generate_series(-71,50,15) As i
203                        CROSS JOIN generate_series(42,70, 25) AS j
204                        CROSS JOIN generate_series(1,2) As m
205                        ) As s)</pgis:gset>
206
207                <pgis:gset ID='MULTILINESTRINGM' GeometryType='MULTILINESTRINGM'>(SELECT ST_Collect(s.the_geom) As the_geom
208                FROM (SELECT ST_MakeLine(ST_SetSRID(ST_MakePointM(i - 0.0821,j + 0.3036,m),4326),ST_SetSRID(ST_MakePointM(j,i,m),4326))  As the_geom
209                FROM generate_series(-71,50,15) As i
210                        CROSS JOIN generate_series(50,70, 25) As j
211                        CROSS JOIN generate_series(1,2) As m
212                        WHERE NOT(i = j)) As s)</pgis:gset>
213
214                <pgis:gset ID='MULTIPOLYGONM' GeometryType='MULTIPOLYGONM'>(
215                        SELECT ST_GeomFromEWKT('SRID=4326;MULTIPOLYGONM(((0 0 2,10 0 1,10 10 -2,0 10 -5,0 0 -5),(5 5 6,7 5 6,7 7 6,5 7 10,5 5 -2)))')  As the_geom
216                        )</pgis:gset>
217                       
218                <!-- replacing crasher with a more harmless curve polygon and circular string -->
219                <pgis:gset ID='CURVEPOLYGON' GeometryType='CURVEPOLYGON'>(SELECT ST_GeomFromEWKT('SRID=4326;CURVEPOLYGON(CIRCULARSTRING(-71.0821 42.3036, -71.4821 42.3036, -71.7821 42.7036, -71.0821 42.7036, -71.0821 42.3036),(-71.1821 42.4036, -71.3821 42.6036, -71.3821 42.4036, -71.1821 42.4036) ) ') As the_geom)</pgis:gset>
220
221                <pgis:gset ID='CIRCULARSTRING' GeometryType='CIRCULARSTRING'>(SELECT ST_GeomFromEWKT('SRID=4326;CIRCULARSTRING(-71.0821 42.3036,-71.4821 42.3036,-71.7821 42.7036,-71.0821 42.7036,-71.0821 42.3036)') As the_geom)</pgis:gset>
222                <pgis:gset ID='MULTISURFACE' GeometryType='MULTISURFACE'>(SELECT ST_GeomFromEWKT('SRID=4326;MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(-71.0821 42.3036, -71.4821 42.3036, -71.7821 42.7036, -71.0821 42.7036, -71.0821 42.3036),(-71.1821 42.4036, -71.3821 42.6036, -71.3821 42.4036, -71.1821 42.4036) ))') As the_geom)</pgis:gset>
223                <!--These are special case geometries -->
224                <pgis:gset ID="Typed Empty Geometries" GeometryType="GEOMETRY" createtable="false">(SELECT
225                        UNION ALL SELECT ST_GeomFromText('POLYGON EMPTY',4326) As the_geom
226                        UNION ALL SELECT ST_GeomFromText('POINT EMPTY',4326) As the_geom
227                        UNION ALL SELECT ST_GeomFromText('MULTIPOINT EMPTY',4326) As the_geom
228                        UNION ALL SELECT ST_GeomFromText('MULTIPOLYGON EMPTY',4326) As the_geom
229                        UNION ALL SELECT ST_GeomFromText('LINESTRING EMPTY',4326) As the_geom
230                        UNION ALL SELECT ST_GeomFromText('MULTILINESTRING EMPTY',4326) As the_geom
231                )
232                </pgis:gset>
233               
234                <pgis:gset ID="Empty Geometry Collection" GeometryType="GEOMETRY" createtable="false">
235                 (ST_GeomFromText('GEOMETRYCOLLECTION EMPTY',4326) As the_geom )
236                </pgis:gset>
237                       
238                <pgis:gset ID="Single NULL" GeometryType="GEOMETRY" createtable="false">(SELECT CAST(Null As geometry) As the_geom)</pgis:gset>
239                <pgis:gset ID="Multiple NULLs" GeometryType="GEOMETRY" createtable="false">(SELECT CAST(Null As geometry) As the_geom FROM generate_series(1,4) As foo)</pgis:gset>
240
241
242        <!-- TODO: Finish off MULTI list -->
243        </pgis:gardens>
244        <!--This is just a placeholder to hold geometries that will crash server when hitting against some functions
245                We'll fix these crashers in 1.4 -->
246                <pgis:gset ID='CurvePolySet' GeometryType='CURVEPOLYGON'>(SELECT ST_LineToCurve(ST_Buffer(ST_SetSRID(ST_Point(i,j),4326), j))  As the_geom
247                                FROM generate_series(-10,50,10) As i
248                                        CROSS JOIN generate_series(40,70, 20) As j
249                                        ORDER BY i, j, i*j)</pgis:gset>
250                <pgis:gset ID='CircularStringSet' GeometryType='CIRCULARSTRING'>(SELECT ST_LineToCurve(ST_Boundary(ST_Buffer(ST_SetSRID(ST_Point(i,j),4326), j)))  As the_geom
251                                FROM generate_series(-10,50,10) As i
252                                        CROSS JOIN generate_series(40,70, 20) As j
253                                        ORDER BY i, j, i*j)</pgis:gset>
254                                       
255                <pgis:gset ID="Collection of Empties" GeometryType="GEOMETRY" createtable="false">(SELECT ST_Collect(ST_GeomFromText('GEOMETRYCOLLECTION EMPTY',4326), ST_GeomFromText('POLYGON EMPTY',4326)) As the_geom
256                        UNION ALL SELECT ST_COLLECT(ST_GeomFromText('POLYGON EMPTY',4326),ST_GeomFromText('TRIANGLE EMPTY',4326))  As the_geom
257                        UNION ALL SELECT ST_Collect(ST_GeomFromText('POINT EMPTY',4326), ST_GeomFromText('MULTIPOINT EMPTY',4326)) As the_geom
258                )</pgis:gset>
259
260        <pgis:gardencrashers>
261
262
263        </pgis:gardencrashers>
264
265        <!-- We deal only with the reference chapter -->
266        <xsl:template match="/">
267<!-- Create logging tables -->
268DROP TABLE IF EXISTS <xsl:value-of select="$var_logtable" />;
269CREATE TABLE <xsl:value-of select="$var_logtable" />(logid serial PRIMARY KEY, log_label text, spatial_class text, func text, g1 text, g2 text, log_start timestamp, log_end timestamp, log_sql text);
270DROP TABLE IF EXISTS <xsl:value-of select="$var_logtable" />_output;
271CREATE TABLE <xsl:value-of select="$var_logtable" />_output(logid integer PRIMARY KEY, log_output xml);
272
273                <xsl:apply-templates select="/book/chapter[@id='reference']" />
274        </xsl:template>
275
276        <xsl:template match='chapter'>
277<!--Start Test table creation, insert, analyze crash test, drop -->
278                <xsl:for-each select="document('')//pgis:gardens/pgis:gset[not(contains(@createtable,'false'))]">
279                        <xsl:variable name='log_label'>table Test <xsl:value-of select="@GeometryType" /></xsl:variable>
280SELECT '<xsl:value-of select="$log_label" />: Start Testing';
281<xsl:variable name='var_sql'>CREATE TABLE pgis_garden (gid serial);
282        SELECT AddGeometryColumn('pgis_garden','the_geom',ST_SRID(the_geom),GeometryType(the_geom),ST_CoordDim(the_geom))
283                        FROM (<xsl:value-of select="." />) As foo limit 1;
284        SELECT AddGeometryColumn('pgis_garden','the_geom_multi',ST_SRID(the_geom),GeometryType(ST_Multi(the_geom)),ST_CoordDim(the_geom))
285                        FROM (<xsl:value-of select="." />) As foo limit 1;</xsl:variable>
286INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start, log_sql)
287VALUES('<xsl:value-of select="$log_label" /> AddGeometryColumn','AddGeometryColumn', '<xsl:value-of select="@GeometryType" />', clock_timestamp(),
288    '<xsl:call-template name="escapesinglequotes"><xsl:with-param name="arg1"><xsl:value-of select="$var_sql" /></xsl:with-param></xsl:call-template>');
289BEGIN;
290        <xsl:value-of select="$var_sql" />
291        <xsl:value-of select="$var_logupdatesql" />
292COMMIT;
293
294SELECT '<xsl:value-of select="$log_label" /> Geometry index: Start Testing <xsl:value-of select="@ID" />';
295INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start) VALUES('<xsl:value-of select="$log_label" /> gist index Geometry','CREATE gist index geometry', '<xsl:value-of select="@ID" />', clock_timestamp());
296BEGIN;
297        CREATE INDEX idx_pgis_geom_gist ON pgis_garden USING gist(the_geom);
298        <xsl:value-of select="$var_logupdatesql" />
299COMMIT;
300SELECT '<xsl:value-of select="$log_label" /> geometry index: End Testing <xsl:value-of select="@ID" />';
301
302INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start)
303VALUES('<xsl:value-of select="$log_label" /> insert data Geometry','insert data', '<xsl:value-of select="@ID" />', clock_timestamp());
304
305BEGIN;
306        INSERT INTO pgis_garden(the_geom, the_geom_multi)
307        SELECT the_geom, ST_Multi(the_geom)
308        FROM (<xsl:value-of select="." />) As foo;
309        <xsl:value-of select="$var_logupdatesql" />
310COMMIT;
311               
312INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start)
313VALUES('<xsl:value-of select="$log_label" /> UpdateGeometrySRID','UpdateGeometrySRID', '<xsl:value-of select="@GeometryType" />', clock_timestamp());
314BEGIN;
315        SELECT UpdateGeometrySRID('pgis_garden', 'the_geom', 4269);
316        <xsl:value-of select="$var_logupdatesql" />
317COMMIT;
318
319INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start)
320VALUES('<xsl:value-of select="$log_label" /> vacuum analyze Geometry','vacuum analyze Geometry', '<xsl:value-of select="@ID" />', clock_timestamp());
321VACUUM ANALYZE pgis_garden;
322<xsl:value-of select="$var_logupdatesql" />
323
324INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start)
325VALUES('<xsl:value-of select="$log_label" /> DropGeometryColumn','DropGeometryColumn', '<xsl:value-of select="@GeometryType" />', clock_timestamp());
326
327BEGIN;
328        SELECT DropGeometryColumn ('pgis_garden','the_geom');
329        <xsl:value-of select="$var_logupdatesql" />
330COMMIT;
331INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start)
332VALUES('<xsl:value-of select="$log_label" /> DropGeometryTable','DropGeometryTable', '<xsl:value-of select="@ID" />', clock_timestamp());
333
334BEGIN;
335        SELECT DropGeometryTable ('pgis_garden');
336        <xsl:value-of select="$var_logupdatesql" />
337COMMIT;
338SELECT '<xsl:value-of select="$log_label" />: End Testing  <xsl:value-of select="@ID" />';
339        <xsl:text>
340
341        </xsl:text>
342SELECT '<xsl:value-of select="$log_label" /> Geography: Start Testing <xsl:value-of select="@ID" />';
343INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start) VALUES('<xsl:value-of select="$log_label" /> Create Table / Add data - Geography','CREATE TABLE geography', '<xsl:value-of select="@ID" />', clock_timestamp());
344BEGIN;
345        CREATE TABLE pgis_geoggarden (gid serial PRIMARY KEY, the_geog geography(<xsl:value-of select="@GeometryType" />, 4326));
346        INSERT INTO pgis_geoggarden(the_geog)
347        SELECT the_geom
348        FROM (<xsl:value-of select="." />) As foo;
349        <xsl:value-of select="$var_logupdatesql" />
350COMMIT;
351SELECT '<xsl:value-of select="$log_label" /> Geography: End Testing <xsl:value-of select="@ID" />';
352
353SELECT '<xsl:value-of select="$log_label" /> Geography index: Start Testing <xsl:value-of select="@ID" />';
354INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start) VALUES('<xsl:value-of select="$log_label" /> gist index Geography','CREATE gist index geography', '<xsl:value-of select="@ID" />', clock_timestamp());
355BEGIN;
356        CREATE INDEX idx_pgis_geoggarden_geog_gist ON pgis_geoggarden USING gist(the_geog);
357        <xsl:value-of select="$var_logupdatesql" />
358COMMIT;
359SELECT '<xsl:value-of select="$log_label" /> Geography index: End Testing <xsl:value-of select="@ID" />';
360
361
362<!-- vacuum analyze can't be put in a commit so we can't completely tell if it completes if it doesn't crash -->
363INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start, log_sql) VALUES('<xsl:value-of select="$log_label" /> vacuum analyze Geography','analyze geography table', '<xsl:value-of select="@ID" />', clock_timestamp(),
364    'VACUUM ANALYZE pgis_geoggarden;');
365VACUUM ANALYZE pgis_geoggarden;
366        <xsl:value-of select="$var_logupdatesql" />
367
368INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start) VALUES('<xsl:value-of select="$log_label" /> drop Geography table','drop geography table', '<xsl:value-of select="@ID" />', clock_timestamp());
369BEGIN;
370    SELECT 'BEFORE DROP' As look_at, * FROM geography_columns;
371        DROP TABLE pgis_geoggarden;
372        SELECT 'AFTER DROP' As look_at, * FROM geography_columns;
373        <xsl:value-of select="$var_logupdatesql" />
374COMMIT;
375SELECT '<xsl:value-of select="$log_label" /> Geography: End Testing';
376        <xsl:text>
377
378        </xsl:text>
379                </xsl:for-each>
380<!--End Test table creation, insert, drop  -->
381
382<!--Start test on operators  -->
383        <xsl:for-each select="sect1[contains(@id,'Operator')]/refentry">
384                <xsl:sort select="@id"/>
385                <xsl:for-each select="refsynopsisdiv/funcsynopsis/funcprototype">
386                        <xsl:variable name='fnname'><xsl:value-of select="funcdef/function"/></xsl:variable>
387                        <xsl:variable name='fndef'><xsl:value-of select="." /></xsl:variable>
388                        <xsl:for-each select="document('')//pgis:gardens/pgis:gset">
389                        <!--Store first garden sql geometry from -->
390                                        <xsl:variable name="from1"><xsl:value-of select="." /></xsl:variable>
391                                        <xsl:variable name='geom1type'><xsl:value-of select="@GeometryType"/></xsl:variable>
392                                        <xsl:variable name='geom1id'><xsl:value-of select="@ID"/></xsl:variable>
393                                        <xsl:variable name='log_label'><xsl:value-of select="$fnname" /><xsl:text> </xsl:text><xsl:value-of select="$geom1id" /> against other types</xsl:variable>
394                SELECT '<xsl:value-of select="$log_label" />: Start Testing ';
395                <xsl:for-each select="document('')//pgis:gardens/pgis:gset">
396                <xsl:choose>
397                          <xsl:when test="contains($fndef, 'geography')">
398                          INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, g2, log_start, log_sql)
399                                VALUES('<xsl:value-of select="$log_label" /> Geography <xsl:value-of select="$geom1id" /><xsl:text> </xsl:text><xsl:value-of select="@ID" />','<xsl:value-of select="$fnname" />', '<xsl:value-of select="$geom1id" />','<xsl:value-of select="@ID" />', clock_timestamp(),
400                                '<xsl:call-template name="escapesinglequotes">
401 <xsl:with-param name="arg1">SELECT ST_AsEWKT(foo1.the_geom) as ewktgeog1, ST_AsEWKT(foo2.the_geom) as ewktgeog2, geography(foo1.the_geom) <xsl:value-of select="$fnname" /> geography(foo2.the_geom) As geog1_op_geog2
402                                        FROM (<xsl:value-of select="$from1" />) As foo1 CROSS JOIN (<xsl:value-of select="." />) As foo2
403                                        WHERE (geography(foo1.the_geom) <xsl:value-of select="$fnname" /> geography(foo2.the_geom)) = true OR
404                                                (geography(foo1.the_geom) <xsl:value-of select="$fnname" /> geography(foo2.the_geom)) = false;</xsl:with-param>
405</xsl:call-template>');
406
407                        SELECT 'Geography <xsl:value-of select="$fnname" /><xsl:text> </xsl:text><xsl:value-of select="@ID" />: Start Testing <xsl:value-of select="$geom1id" />, <xsl:value-of select="@ID" />';
408                        BEGIN;
409                            <xsl:value-of select="$var_logresultsasxml" />
410                                <xsl:value-of select="$var_logupdatesql" />
411                        COMMIT;
412                        </xsl:when>
413                        <xsl:otherwise>
414                        SELECT 'Geometry <xsl:value-of select="$fnname" /><xsl:text> </xsl:text><xsl:value-of select="@ID" />: Start Testing <xsl:value-of select="$geom1id" />, <xsl:value-of select="@ID" />';
415                         INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, g2, log_start, log_sql)
416                                VALUES('<xsl:value-of select="$log_label" /> Geometry <xsl:value-of select="$geom1id" /><xsl:text> </xsl:text><xsl:value-of select="@ID" />','<xsl:value-of select="$fnname" />', '<xsl:value-of select="$geom1id" />','<xsl:value-of select="@ID" />', clock_timestamp(),
417                                '<xsl:call-template name="escapesinglequotes">
418 <xsl:with-param name="arg1">SELECT ST_AsEWKT(foo1.the_geom) as ewktgeom1, ST_AsEWKT(foo2.the_geom) as ewktgeom2, foo1.the_geom <xsl:value-of select="$fnname" /> foo2.the_geom As geom1_op_geom2
419                                                FROM (<xsl:value-of select="$from1" />) As foo1 CROSS JOIN (<xsl:value-of select="." />) As foo2
420                                                WHERE (foo1.the_geom <xsl:value-of select="$fnname" /> foo2.the_geom) = true OR
421                                                (foo1.the_geom <xsl:value-of select="$fnname" /> foo2.the_geom) = false;</xsl:with-param></xsl:call-template>');
422
423                        BEGIN;
424                                <xsl:value-of select="$var_logresultsasxml" />
425                                <xsl:value-of select="$var_logupdatesql" />
426                        COMMIT;
427                        </xsl:otherwise>
428                </xsl:choose>
429                                        </xsl:for-each>
430                SELECT '<xsl:value-of select="$fnname" /><xsl:text> </xsl:text><xsl:value-of select="@ID" />: End Testing <xsl:value-of select="@GeometryType" /> against other types';
431                                </xsl:for-each>
432                        </xsl:for-each>
433        </xsl:for-each>
434<!--End test on operators -->
435<!-- Start regular function checks excluding operators -->
436                <xsl:for-each select="sect1[not(contains(@id,'Operator'))]/refentry">
437                <xsl:sort select="@id"/>
438
439                        <xsl:for-each select="refsynopsisdiv/funcsynopsis/funcprototype">
440<!--Create dummy paramaters to be used later -->
441                                <xsl:variable name='fnfakeparams'><xsl:call-template name="replaceparams"><xsl:with-param name="func" select="." /></xsl:call-template></xsl:variable>
442                                <xsl:variable name='fnargs'><xsl:call-template name="listparams"><xsl:with-param name="func" select="." /></xsl:call-template></xsl:variable>
443                                <xsl:variable name='fnname'><xsl:value-of select="funcdef/function"/></xsl:variable>
444                                <xsl:variable name='fndef'><xsl:value-of select="funcdef"/></xsl:variable>
445                                <xsl:variable name='numparams'><xsl:value-of select="count(paramdef/parameter)" /></xsl:variable>
446                                <xsl:variable name='numparamgeoms'><xsl:value-of select="count(paramdef/type[contains(text(),'geometry') or contains(text(),'geography') or contains(text(),'box') or contains(text(), 'bytea')]) + count(paramdef/parameter[contains(text(),'WKT')]) + count(paramdef/parameter[contains(text(),'geomgml')])" /></xsl:variable>
447                                <xsl:variable name='numparamgeogs'><xsl:value-of select="count(paramdef/type[contains(text(),'geography')] )" /></xsl:variable>
448                                <xsl:variable name='log_label'><xsl:value-of select="funcdef/function" />(<xsl:value-of select="$fnargs" />)</xsl:variable>
449
450                                <xsl:variable name="geoftype">
451                                  <!--Conditionally instantiate a value to be assigned to the variable -->
452                                  <xsl:choose>
453                                        <xsl:when test="$numparamgeoms > '0'">
454                                          <xsl:value-of select="'Geometry'"/>
455                                        </xsl:when>
456                                        <xsl:when test="$numparamgeogs > '0'">
457                                          <xsl:value-of select="'Geography'"/>
458                                        </xsl:when>
459                                        <xsl:otherwise>
460                                          <xsl:value-of select="'Other'"/>
461                                        </xsl:otherwise>
462                                  </xsl:choose>
463                                </xsl:variable>
464                                <!-- For each function prototype generate a test sql statement -->
465                                <xsl:choose>
466<!--Test functions that take no arguments and take no geometries/geographies -->
467        <xsl:when test="($numparamgeoms = '0' and $numparamgeogs = '0') and not(contains($fnexclude,funcdef/function))">SELECT  'Starting <xsl:value-of select="funcdef/function" />(<xsl:value-of select="$fnargs" />)';
468INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, log_start, log_sql)
469                                VALUES('<xsl:value-of select="$log_label" /> <xsl:value-of select="$geoftype" />','<xsl:value-of select="$fnname" />', clock_timestamp(),
470                                    '<xsl:call-template name="escapesinglequotes">
471 <xsl:with-param name="arg1">SELECT  <xsl:value-of select="funcdef/function" />(<xsl:value-of select="$fnfakeparams" />) As output;</xsl:with-param></xsl:call-template>');
472       
473BEGIN;
474    <xsl:value-of select="$var_logresultsasxml" />
475        <xsl:value-of select="$var_logupdatesql" />     
476COMMIT;
477SELECT  'Ending <xsl:value-of select="funcdef/function" />(<xsl:value-of select="$fnargs" />)';
478        </xsl:when>
479<!--Start Test aggregate and unary functions for both geometry and geography -->
480<!-- put functions that take only one geometry/geography no need to cross with another geom collection, these are unary geom, aggregates, and so forth -->
481        <xsl:when test="($numparamgeoms = '1' or $numparamgeogs = '1')  and not(contains($fnexclude,funcdef/function))" >
482                <xsl:for-each select="document('')//pgis:gardens/pgis:gset">
483                SELECT '<xsl:value-of select="$geoftype" /> <xsl:value-of select="$fnname" /><xsl:text> </xsl:text><xsl:value-of select="@ID" />: Start Testing';
484
485        INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, log_start, log_sql)
486                                VALUES('<xsl:value-of select="$log_label" /> <xsl:value-of select="$geoftype" />  <xsl:text> </xsl:text><xsl:value-of select="@ID" /><xsl:text> </xsl:text>','<xsl:value-of select="$fnname" />', '<xsl:value-of select="@ID" />', clock_timestamp(),
487                                '<xsl:call-template name="escapesinglequotes">
488 <xsl:with-param name="arg1">SELECT <xsl:value-of select="$fnname" />(<xsl:value-of select="$fnfakeparams" />) As result
489                                                        FROM (<xsl:value-of select="." />) As foo1
490                                LIMIT 3;</xsl:with-param></xsl:call-template>');
491BEGIN;
492    <xsl:value-of select="$var_logresultsasxml" />
493        <xsl:value-of select="$var_logupdatesql" />     
494COMMIT;           
495                        SELECT '<xsl:value-of select="$geoftype" /> <xsl:value-of select="$fnname" /><xsl:text> </xsl:text><xsl:value-of select="@ID" />: End Testing';
496                </xsl:for-each>
497        </xsl:when>
498
499<!--Functions more than 1 args not already covered this will cross every geometry type with every other -->
500        <xsl:when test="not(contains($fnexclude,funcdef/function))">
501                <xsl:for-each select="document('')//pgis:gardens/pgis:gset">
502        <!--Store first garden sql geometry from -->
503                        <xsl:variable name="from1"><xsl:value-of select="." /></xsl:variable>
504                        <xsl:variable name='geom1type'><xsl:value-of select="@GeometryType"/></xsl:variable>
505                        <xsl:variable name='geom1id'><xsl:value-of select="@ID"/></xsl:variable>
506SELECT '<xsl:value-of select="$fnname" /> <xsl:text> </xsl:text><xsl:value-of select="@ID" />(<xsl:value-of select="$fnargs" />): Start Testing <xsl:value-of select="$geom1id" /> against other types';
507                                <xsl:for-each select="document('')//pgis:gardens/pgis:gset">
508                        <xsl:choose>
509                          <xsl:when test="($numparamgeogs > '0' or $numparamgeoms > '0')">
510        INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, g2,  log_start, log_sql)
511                                VALUES('<xsl:value-of select="$log_label" /> <xsl:value-of select="$geoftype" /> <xsl:text> </xsl:text> <xsl:value-of select="@ID" />','<xsl:value-of select="$fnname" />','<xsl:value-of select="$geom1id" />', '<xsl:value-of select="@ID" />', clock_timestamp(),
512                                                '<xsl:call-template name="escapesinglequotes">
513 <xsl:with-param name="arg1">SELECT <xsl:value-of select="$fnname" />(<xsl:value-of select="$fnfakeparams" />) As result, ST_AsText(foo1.the_geom) As ref1_geom, ST_AsText(foo2.the_geom) As ref2_geom
514        FROM (<xsl:value-of select="$from1" />) As foo1 CROSS JOIN (<xsl:value-of select="." />) As foo2
515                        LIMIT 2;</xsl:with-param></xsl:call-template>');
516
517                        BEGIN;
518                                 <xsl:value-of select="$var_logresultsasxml" />
519                                 <xsl:value-of select="$var_logupdatesql" />
520                        COMMIT;
521                        </xsl:when>
522                          <xsl:otherwise>
523                                INSERT INTO <xsl:value-of select="$var_logtable" />(log_label, func, g1, g2, log_start, log_sql)
524                                VALUES('<xsl:value-of select="$log_label" /> Other <xsl:text> </xsl:text><xsl:value-of select="$geom1id" /><xsl:text> </xsl:text><xsl:value-of select="@ID" />','<xsl:value-of select="$fnname" />', '<xsl:value-of select="$geom1id" />','<xsl:value-of select="@DI" />', clock_timestamp(),
525                                '<xsl:call-template name="escapesinglequotes">
526 <xsl:with-param name="arg1">SELECT <xsl:value-of select="$fnname" />(<xsl:value-of select="$fnfakeparams" />)</xsl:with-param></xsl:call-template>');
527
528                                SELECT 'Other <xsl:value-of select="$fnname" /><xsl:text> </xsl:text><xsl:value-of select="@ID" />(<xsl:value-of select="$fnargs" />): Start Testing <xsl:value-of select="$geom1id" />, <xsl:value-of select="@GeometryType" />';
529                                BEGIN;
530                                 <xsl:value-of select="$var_logresultsasxml" />
531                                 <xsl:value-of select="$var_logupdatesql" />
532                                COMMIT;
533                          </xsl:otherwise>
534                        </xsl:choose>
535               
536        SELECT '<xsl:value-of select="$fnname" />(<xsl:value-of select="$fnargs" />) <xsl:text> </xsl:text> <xsl:value-of select="@ID" />: End Testing <xsl:value-of select="$geom1id" />, <xsl:value-of select="@GeometryType" />';
537                <xsl:text>
538
539                </xsl:text>
540                        </xsl:for-each>
541SELECT '<xsl:value-of select="$fnname" /><xsl:text> </xsl:text><xsl:value-of select="@ID" />(<xsl:value-of select="$fnargs" />): End Testing <xsl:value-of select="@GeometryType" /> against other types';
542                </xsl:for-each>
543                </xsl:when>
544        </xsl:choose>
545                        </xsl:for-each>
546                </xsl:for-each>
547                <!-- flag primary grouping the functions belong in -->
548                UPDATE <xsl:value-of select="$var_logtable" /> SET spatial_class = 'geography' WHERE log_label ILIKE '%geography%' AND spatial_class IS NULL;
549                UPDATE <xsl:value-of select="$var_logtable" /> SET spatial_class = 'geometry' WHERE log_label ILIKE '%geometry%' or log_label ILIKE '%other%' AND spatial_class IS NULL;
550
551        </xsl:template>
552
553        <!--macro to replace func args with dummy var args -->
554        <xsl:template name="replaceparams">
555                <xsl:param name="func" />
556                <xsl:for-each select="$func">
557                        <xsl:for-each select="paramdef">
558                                <xsl:choose>
559                                        <xsl:when test="contains(parameter, 'matrix') or contains(parameter, 'Matrix')">
560                                                <xsl:value-of select="$var_matrix" />
561                                        </xsl:when>
562                                        <xsl:when test="contains(parameter, 'distance')">
563                                                <xsl:value-of select="$var_distance" />
564                                        </xsl:when>
565                                        <xsl:when test="contains(parameter, 'srid')">
566                                                <xsl:value-of select="$var_srid" />
567                                        </xsl:when>
568                                        <xsl:when test="contains(parameter, 'position')">
569                                                <xsl:value-of select="$var_position" />
570                                        </xsl:when>
571                                        <xsl:when test="contains(parameter, 'NDR')">
572                                                '<xsl:value-of select="$var_NDRXDR" />'
573                                        </xsl:when>
574                                        <xsl:when test="contains(parameter, 'gj_version')">
575                                                <xsl:value-of select="$var_gj_version" />
576                                        </xsl:when>
577                                        <xsl:when test="contains(parameter, 'version') and position() = 2">
578                                                <xsl:value-of select="$var_version1" />
579                                        </xsl:when>
580                                        <xsl:when test="(contains(parameter, 'version'))">
581                                                <xsl:value-of select="$var_version2" />
582                                        </xsl:when>
583                                        <xsl:when test="(contains(parameter,'geomgml'))">
584                                                <xsl:text>ST_AsGML(foo1.the_geom)</xsl:text>
585                                        </xsl:when>
586                                        <xsl:when test="(contains(parameter,'geomkml'))">
587                                                <xsl:text>ST_AsKML(foo1.the_geom)</xsl:text>
588                                        </xsl:when>
589                                        <xsl:when test="(contains(type,'box') or type = 'geometry' or type = 'geometry ' or contains(type,'geometry set')) and (position() = 1 or count($func/paramdef/type[contains(text(),'geometry') or contains(text(),'box') or contains(text(), 'WKT') or contains(text(), 'bytea')]) = '1')">
590                                                <xsl:text>foo1.the_geom</xsl:text>
591                                        </xsl:when>
592                                        <xsl:when test="(type = 'geography' or type = 'geography ' or contains(type,'geography set')) and (position() = 1 or count($func/paramdef/type[contains(text(),'geography')]) = '1' )">
593                                                <xsl:text>geography(foo1.the_geom)</xsl:text>
594                                        </xsl:when>
595                                        <xsl:when test="contains(type,'box') or type = 'geometry' or type = 'geometry '">
596                                                <xsl:text>foo2.the_geom</xsl:text>
597                                        </xsl:when>
598                                        <xsl:when test="type = 'geography' or type = 'geography '">
599                                                <xsl:text>geography(foo2.the_geom)</xsl:text>
600                                        </xsl:when>
601                                        <xsl:when test="contains(type, 'geometry[]') and count($func/paramdef/type[contains(text(),'geometry') or contains(text(),'box') or contains(text(), 'WKT') or contains(text(), 'bytea')]) = '1'">
602                                                ARRAY[foo1.the_geom]
603                                        </xsl:when>
604                                        <xsl:when test="contains(type, 'geometry[]')">
605                                                ARRAY[foo2.the_geom]
606                                        </xsl:when>
607                                        <xsl:when test="contains(parameter, 'EWKT')">
608                                                <xsl:text>ST_AsEWKT(foo1.the_geom)</xsl:text>
609                                        </xsl:when>
610                                        <xsl:when test="contains(parameter, 'WKT')">
611                                                <xsl:text>ST_AsText(foo1.the_geom)</xsl:text>
612                                        </xsl:when>
613                                        <xsl:when test="contains(parameter, 'EWKB')">
614                                                <xsl:text>ST_AsEWKB(foo1.the_geom)</xsl:text>
615                                        </xsl:when>
616                                        <xsl:when test="contains(type, 'bytea')">
617                                                <xsl:text>ST_AsBinary(foo1.the_geom)</xsl:text>
618                                        </xsl:when>
619                                        <xsl:when test="contains(type, 'float') or contains(type, 'double')">
620                                                <xsl:value-of select="$var_float1" />
621                                        </xsl:when>
622                                        <xsl:when test="contains(type, 'spheroid')">
623                                                <xsl:value-of select="$var_spheroid" />
624                                        </xsl:when>
625                                        <xsl:when test="contains(type, 'integer') and position() = 2">
626                                                <xsl:value-of select="$var_integer1" />
627                                        </xsl:when>
628                                        <xsl:when test="contains(type, 'integer')">
629                                                <xsl:value-of select="$var_integer2" />
630                                        </xsl:when>
631                                        <xsl:when test="contains(type, 'text')">
632                                                <xsl:value-of select="$var_text" />
633                                        </xsl:when>
634                                        <xsl:when test="contains(type, 'varchar')">
635                                                <xsl:value-of select="$var_varchar" />
636                                        </xsl:when>
637                                        <xsl:when test="contains(type,'timestamp') or type = 'date'">
638                                                <xsl:text>'2009-01-01'</xsl:text>
639                                        </xsl:when>
640                                        <xsl:when test="contains(type,'boolean')">
641                                                <xsl:value-of select="$var_boolean" />
642                                        </xsl:when>
643                                </xsl:choose>
644                                <xsl:if test="position()&lt;last()"><xsl:text>, </xsl:text></xsl:if>
645                        </xsl:for-each>
646                </xsl:for-each>
647        </xsl:template>
648
649        <!--macro to pull out function parameter names so we can provide a pretty arg list prefix for each function -->
650        <xsl:template name="listparams">
651                <xsl:param name="func" />
652                <xsl:for-each select="$func">
653                        <xsl:if test="count(paramdef/parameter) &gt; 0"> </xsl:if>
654                        <xsl:for-each select="paramdef">
655                                <xsl:choose>
656                                        <xsl:when test="count(parameter) &gt; 0">
657                                                <xsl:value-of select="parameter" />
658                                        </xsl:when>
659                                </xsl:choose>
660                                <xsl:if test="position()&lt;last()"><xsl:text>, </xsl:text></xsl:if>
661                        </xsl:for-each>
662                </xsl:for-each>
663        </xsl:template>
664       
665        <!-- copied from http://www.thedumbterminal.co.uk/php/knowledgebase/?action=view&id=94 -->
666    <xsl:template name="escapesinglequotes">
667     <xsl:param name="arg1"/>
668     <xsl:variable name="apostrophe">'</xsl:variable>
669     <xsl:choose>
670      <!-- this string has at least on single quote -->
671      <xsl:when test="contains($arg1, $apostrophe)">
672      <xsl:if test="string-length(normalize-space(substring-before($arg1, $apostrophe))) > 0"><xsl:value-of select="substring-before($arg1, $apostrophe)" disable-output-escaping="yes"/>''</xsl:if>
673       <xsl:call-template name="escapesinglequotes">
674        <xsl:with-param name="arg1"><xsl:value-of select="substring-after($arg1, $apostrophe)" disable-output-escaping="yes"/></xsl:with-param>
675       </xsl:call-template>
676      </xsl:when>
677      <!-- no quotes found in string, just print it -->
678      <xsl:when test="string-length(normalize-space($arg1)) > 0"><xsl:value-of select="normalize-space($arg1)"/></xsl:when>
679     </xsl:choose>
680    </xsl:template>
681
682</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.