File: postgis_comments.sql.xsl

package info (click to toggle)
postgis 3.5.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 69,528 kB
  • sloc: ansic: 162,229; sql: 93,970; xml: 53,139; cpp: 12,646; perl: 5,658; sh: 5,369; makefile: 3,435; python: 1,205; yacc: 447; lex: 151; pascal: 58
file content (56 lines) | stat: -rw-r--r-- 4,080 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:db="http://docbook.org/ns/docbook"
>
<!-- ********************************************************************
     ********************************************************************
	 Copyright 2008, Regina Obe
 License: BSD-3-Clause
	 Purpose: This is an xsl transform that generates PostgreSQL COMMENT ON FUNCTION ddl
	 statements from postgis xml doc reference
     ******************************************************************** -->
	<xsl:include href="common_utils.xsl" />
	<xsl:include href="common_comments.xsl" />

	<xsl:output method="text" />

	<!-- We deal only with the reference chapter -->
        <xsl:template match="/">
                <xsl:apply-templates select="/db:book/db:chapter[@xml:id='reference']" />
        </xsl:template>

        <xsl:template match="db:chapter">
		<xsl:variable name="ap"><xsl:text>'</xsl:text></xsl:variable>
<!-- Pull out the purpose section for each ref entry and strip whitespace and put in a variable to be tagged unto each function comment  -->
		<xsl:for-each select="db:section[not(contains(@xml:id,'Operator') or contains(@xml:id,'sfcgal') or contains(@xml:id,'GUC') )]/db:refentry">
		  <xsl:variable name='plaincomment'>
		  	<xsl:value-of select="normalize-space(translate(translate(db:refnamediv/db:refpurpose,'&#x0d;&#x0a;', ' '), '&#09;', ' '))"/>
		  </xsl:variable>
<!-- Replace apostrophes with 2 apostrophes needed for escaping in SQL -->
		<xsl:variable name='comment'>
			<xsl:call-template name="globalReplace">
				<xsl:with-param name="outputString" select="$plaincomment"/>
				<xsl:with-param name="target" select="$ap"/>
				<xsl:with-param name="replacement" select="''"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:choose>
<!-- If this is a postgis type grab the ref entry summary and refname to make type comment -->
<xsl:when test="parent::db:section[@xml:id='PostGIS_Types'] and not(contains(db:refnamediv/db:refname, 'raster') or contains(db:refnamediv/db:refname, 'geomval'))">
	COMMENT ON TYPE <xsl:value-of select="db:refnamediv/db:refname" /> IS 'postgis type: <xsl:value-of select='$comment' />';
</xsl:when>
		</xsl:choose>
<!-- For each function prototype generate the DDL comment statement
	If its input has the word set we no it is an aggregate
	If its input has the word winset we know it is a window function but comment signature of those are the same just have to strip off the winset
	Do not output OUT params since they define output rather than act as input and do not put a comma after argument just before an OUT parameter
	TODO:  revise case to handle any set, winset data type (right now hardcoded geometry, any element-->
		<xsl:for-each select="db:refsynopsisdiv/db:funcsynopsis/db:funcprototype">
COMMENT ON <xsl:choose><xsl:when test="contains(db:paramdef/db:type,' set')">AGGREGATE</xsl:when><xsl:otherwise>FUNCTION</xsl:otherwise></xsl:choose><xsl:text> </xsl:text> <xsl:value-of select="db:funcdef/db:function" />(<xsl:for-each select="db:paramdef"><xsl:choose><xsl:when test="count(db:parameter) &gt; 0">
<xsl:choose><xsl:when test="contains(db:parameter,'OUT')"></xsl:when><xsl:when test="contains(db:type,'anyelement set')">anyelement</xsl:when><xsl:when test="contains(db:type,'geometry set')">geometry</xsl:when><xsl:when test="contains(db:type,'anyelement winset')">anyelement</xsl:when><xsl:when test="contains(db:type,'geometry winset')">geometry</xsl:when><xsl:when test="contains(db:type,'geography winset')">geography</xsl:when><xsl:otherwise><xsl:value-of select="db:type" /></xsl:otherwise></xsl:choose><xsl:if test="position()&lt;last() and not(contains(db:parameter,'OUT')) and not(contains(following-sibling::paramdef[1],'OUT'))"><xsl:text>, </xsl:text></xsl:if></xsl:when>
</xsl:choose></xsl:for-each>) IS '<xsl:call-template name="listparams"><xsl:with-param name="func" select="." /></xsl:call-template> <xsl:value-of select='$comment' />';
			</xsl:for-each>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>