Project

Profile

Help

How to connect?
Download (5.52 KB) Statistics
| Branch: | Revision:

he / tools / genFunctionDoc.xsl @ 5d25f10d

1
<?xml version="1.0" encoding="UTF-8"?> 
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
  xmlns:math="http://www.w3.org/2005/xpath-functions/math"
5
  xmlns:doc="http://www.saxonica.com/ns/doc" xmlns:sDoc="http://www.saxonica.com/ns/doc/functions"
6
  xmlns:fos="http://www.w3.org/xpath-functions/spec/namespace"
7
  xmlns:map="http://www.w3.org/2005/xpath-functions/map"
8
  exclude-result-prefixes="xs math sDoc fos map" version="3.0">
9

    
10
  <xsl:param name="GitHub" as="xs:string"/>
11

    
12
  <xsl:output method="xml" indent="yes"/>
13

    
14
  <xsl:mode on-no-match="shallow-copy"/>
15

    
16
  <xsl:variable name="catalog"
17
    select="doc(resolve-uri(replace(section/@catalog,'\$\{GitHub\}',$GitHub),base-uri(.)))"
18
    doc:doc="The function catalog that contains the signatures for the functions in this section"/>
19
  <xsl:variable name="namespace" select="section/@namespace"
20
    doc:doc="The namespace for these functions"/>
21
  <xsl:variable name="spec" select="section/@spec"
22
    doc:doc="The specification within which this set of functions is defined"/>
23

    
24
  <xsl:variable name="defaults" select="section/defaults"
25
    doc:doc="Default values for parts of the descriptions of each function"/>
26
  <xsl:variable name="implementation-doc" select="doc('../src/viewer_appJS/doc/implement.xml')"
27
    as="document-node()" doc:doc="Document containing implementation status descriptions"/>
28
  <xsl:variable name="implementation" select="$implementation-doc/implement"
29
    doc:doc="Defaults for the implementation status descriptions"/>
30

    
31
  <xsl:variable name="args" as="map(xs:string,xs:string)"
32
    select="map:merge($defaults/arg-descriptions/* ! map:entry(name(.),xs:string(.)))"
33
    doc:doc="Default descriptions for the function arguments, keyed by name.
34
        It helps if the use of argument names is consistent throughout the module."/>
35
  <xsl:variable name="use-last" as="map(*)" select="map{'duplicates':'use-last'}"/>
36

    
37
  <xsl:variable name="implement.saxon" as="map(xs:string,xs:string)"
38
    select="map:merge($implementation/saxon ! map:entry(string(@version),xs:string(.)))"/>
39
  <xsl:variable name="implement.xpath" as="map(xs:string,xs:string)"
40
    select="map:merge($implementation/xpath ! map:entry(string(@version),xs:string(.)))"/>
41
  <xsl:variable name="default.saxon" select="$implementation/default[@id = $spec]/@saxon"/>
42
  <xsl:variable name="default.xpath" select="$implementation/default[@id = $spec]/@xpath"/>
43

    
44
  <xsl:template match="section">
45
    <xsl:copy>
46
      <xsl:sequence select="@id|@title"/>
47
      <xsl:comment>Generated - <xsl:value-of select="current-dateTime()"/></xsl:comment>
48
      <xsl:apply-templates select="h1|function" mode="#current">
49
        <xsl:sort select="@name"/>
50
      </xsl:apply-templates>
51
    </xsl:copy>
52
  </xsl:template>
53
  <xsl:template match="function[@name]">
54
    <function xmlns="http://www.saxonica.com/ns/doc/functions">
55
      <xsl:variable name="args" select="map:merge(($args, (args/* !
56
        map:entry(name(.),xs:string(.)))), $use-last)"/>
57
      <name namespace="{$namespace}">
58
        <xsl:value-of select="@name"/>
59
      </name>
60
      <xsl:apply-templates select="$catalog//fos:function[@name=current()/@name]">
61
        <xsl:with-param name="args" select="$args" tunnel="yes"/>
62
      </xsl:apply-templates>
63

    
64
      <xsl:for-each select="status">
65
        <status>
66
          <xsl:copy-of select="*|text()"/>
67
        </status>
68
      </xsl:for-each>
69
      <xpath>
70
        <xsl:value-of select="(@xpath,$default.xpath,'default')[1]"/>
71
      </xpath>
72
      <saxon-edition>
73
        <xsl:value-of select="(@saxon,$default.saxon,' ')[1]"/>
74
      </saxon-edition>
75
    </function>
76
  </xsl:template>
77
  <xsl:template match="section/h1">
78
    <xsl:copy-of select="."/>
79
  </xsl:template>
80

    
81
  <xsl:template match="fos:* | *">
82
    <xsl:element name="{local-name(.)}" namespace="http://www.saxonica.com/ns/doc/functions">
83
      <xsl:apply-templates select="@*|*|text()" mode="#current"/>
84
    </xsl:element>
85
  </xsl:template>
86
  <xsl:template match="fos:rules | fos:examples | fos:errors | fos:notes "/>
87
  <xsl:template match="fos:function">
88
    <xsl:apply-templates select="*" mode="#current"/>
89
  </xsl:template>
90
  <xsl:template match="fos:summary">
91
    <description xmlns="http://www.saxonica.com/ns/doc/functions">
92
      <xsl:apply-templates select="*" mode="#current"/>
93
    </description>
94
  </xsl:template>
95
  <xsl:template match="loc">
96
    <a xmlns="http://www.saxonica.com/ns/doc/functions">
97
      <xsl:apply-templates select="@*|*|text()" mode="#current"/>
98
    </a>
99
  </xsl:template>
100
  <xsl:template match="fos:proto">
101
    <proto xmlns="http://www.saxonica.com/ns/doc/functions">
102
      <xsl:apply-templates select="(@* except @name),*" mode="#current"/>
103
      <xsl:for-each select="tokenize($spec,'\s+')">
104
        <in-spec>
105
          <xsl:value-of select="."/>
106
        </in-spec>
107
      </xsl:for-each>
108
    </proto>
109
  </xsl:template>
110
  <xsl:template match="fos:arg">
111
    <xsl:param name="args" as="map(xs:string,xs:string)" tunnel="yes"/>
112
    <arg xmlns="http://www.saxonica.com/ns/doc/functions">
113
      <xsl:apply-templates select="@*" mode="#current"/>
114
      <xsl:if test="$args(@name)">
115
        <xsl:attribute name="desc" namespace="" select="$args(@name)"/>
116
      </xsl:if>
117
      <xsl:apply-templates select="*" mode="#current"/>
118
    </arg>
119
  </xsl:template>
120
  
121
  <!-- Fix a link on the file:parent() page  -->
122
  <xsl:template match="loc[@href='#fn.resolve-path']">
123
    <a xmlns="http://www.saxonica.com/ns/doc/functions" href="../resolve-path">
124
      <xsl:apply-templates select="(@* except @href)|*|text()" mode="#current"/>
125
    </a>
126
  </xsl:template>
127

    
128

    
129
</xsl:stylesheet>
(12-12/15)