Project

Profile

Help

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

he / tools / check-tag-links.xsl @ 00082f6f

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:f="urn:local.function"
5
   exclude-result-prefixes="xs f"
6
   version="3.0">
7
   
8
   <!-- Check tag links in the Javadoc files in javadoc-xml/packages/
9
      by comparing against javadoc-xml/javadoc-types.xml 
10
   
11
      Currently only check fully qualified links (i.e. containing '.') i.e. non-local
12
      
13
   -->
14
   
15
   <!-- Choose whether or not to apply post processing filtering of results,
16
      e.g. to only show internal Saxon links which are not found -->
17
   <xsl:param name="filter" select="true()"/>
18
   
19
   <xsl:mode name="filter" on-no-match="shallow-copy"/>
20
   
21
   <xsl:template match="tag[@found eq 'yes']" mode="filter"/>
22
   
23
   <xsl:template match="tag[@found eq 'no'][not(contains(@href, 'saxon'))]" mode="filter"/>
24
   
25
   
26
   <xsl:variable name="javadoc-types" select="doc('../build/javadoc-xml/javadoc-types.xml')"/>
27
   
28
   <xsl:template match="/" name="main">
29
      <xsl:variable name="out1">
30
         <out>
31
            <xsl:for-each select="collection('../build/javadoc-xml/packages/')//package">
32
               <package>
33
                  <xsl:attribute name="id" select="@id"/>
34
                  <xsl:apply-templates select="*" mode="tag-only"/>
35
               </package>
36
            </xsl:for-each>
37
         </out>
38
      </xsl:variable>
39
      
40
      <xsl:variable name="out2">
41
         <xsl:choose>
42
            <xsl:when test="$filter">
43
               <xsl:apply-templates select="$out1" mode="filter"/>
44
            </xsl:when>
45
            <xsl:otherwise>
46
               <xsl:sequence select="$out1"/>
47
            </xsl:otherwise>
48
         </xsl:choose>
49
      </xsl:variable>
50
      
51
      <xsl:sequence select="$out2"/>
52
      
53
      <xsl:for-each select="$out2//tag">
54
         <xsl:message><xsl:value-of select="@to"/> not found: <xsl:value-of select="@href"/></xsl:message>
55
      </xsl:for-each>
56
      
57
   </xsl:template>
58
   
59
   <xsl:template match="*" mode="tag-only">
60
      <xsl:apply-templates select="node()" mode="tag-only"/>
61
   </xsl:template>
62
   
63
   <xsl:template match="text()" mode="tag-only">
64
   </xsl:template>
65
   
66
   <xsl:template match="tag[@kind eq 'see']" mode="tag-only">
67
      
68
      <xsl:variable name="fromPackage" select="ancestor::package/@id" as="xs:string"/>
69
      <xsl:variable name="fromClass" select="ancestor::class/@id" as="xs:string*"/>
70
      
71
      <xsl:if test="contains(., '.')">
72
         <!-- Process link reference much like viewer_app.xsl f:anchor-navigation
73
            - remove substring after (
74
            - if end in ] then remove substring after [
75
            *** filter out non-local links again
76
            - split into package path (e.g. net.sf.saxon.lib) and class name (possible nested class) and member name
77
            - use this to match in javadoc-types.xml
78
         -->
79
         
80
         <xsl:variable name="data-href" select="string(.)"/>
81
         <xsl:variable name="ref"
82
            select="for $a in substring-before($data-href,'(') return if ($a eq '') then $data-href else $a"/>
83
         <xsl:variable name="pageref"
84
            select="if (ends-with($ref, ']')) then substring-before($ref, '[') else $ref"/>
85
         
86
         <xsl:if test="contains($pageref, '.')">
87
            <xsl:variable name="tokens" select="tokenize($pageref,'\.')" as="xs:string*"/>
88
            <xsl:variable name="paths" as="xs:string*"
89
               select="for $t in 1 to count($tokens),
90
               $ch in substring($tokens[$t],1,1) return
91
               if (upper-case($ch) eq $ch) then
92
               concat('/',$tokens[$t]) else concat('.',$tokens[$t])"/>
93
            
94
            <xsl:variable name="path" select="substring(string-join($paths,''),2)"/>
95
            <xsl:variable name="paths2" select="tokenize($path, '/')"/>
96
            
97
            
98
            <!-- If $paths2[last()] contains '#', then split here for member name.
99
               But note that must check whether path is for nested class (i.e. $paths2 length 3)
100
               before splitting members. -->
101
            
102
            <tag fromPackage="{$fromPackage}" fromClass="{$fromClass}" href="{$paths2}">
103
               <xsl:choose>
104
                  <xsl:when test="contains($paths2[last()], '#')">
105
                     <!-- member link -->
106
                     <xsl:variable name="package" select="$javadoc-types//j[@in eq 'p'][@id eq $paths2[1]]"/>
107
                     <xsl:choose>
108
                        <xsl:when test="count($paths2) eq 3">
109
                           <xsl:variable name="class" select="$package/j[@in eq 'c'][@id eq $paths2[2]]"/>
110
                           <xsl:variable name="nested-class" select="$class/j[@in eq 'c'][@id eq
111
                              substring-before($paths2[3], '#')]"/>
112
                           <xsl:variable name="member" select="$nested-class/j[@id eq
113
                              substring-after($paths2[3], '#')]"/>
114
                           <xsl:attribute name="to">nested-class-member</xsl:attribute>
115
                           <xsl:attribute name="found" select="if (exists($member)) then 'yes' else
116
                              'no'"/>
117
                        </xsl:when>
118
                        <xsl:otherwise>
119
                           <xsl:variable name="class" select="$package/j[@in eq 'c'][@id eq
120
                              substring-before($paths2[2], '#')]"/>
121
                           <xsl:variable name="member" select="$class/j[@id eq
122
                              substring-after($paths2[2], '#')]"/>
123
                           <xsl:attribute name="to">class-member</xsl:attribute>
124
                           <xsl:attribute name="found" select="if (exists($member)) then 'yes' else
125
                              'no'"/>
126
                        </xsl:otherwise>
127
                     </xsl:choose>
128
                  </xsl:when>
129
                  <xsl:otherwise>
130
                     <!-- class link -->
131
                     <xsl:variable name="package" select="$javadoc-types//j[@in eq 'p'][@id eq $paths2[1]]"/>
132
                     <xsl:variable name="class" select="$package/j[@in eq 'c'][@id eq $paths2[2]]"/>
133
                     <xsl:choose>
134
                        <xsl:when test="count($paths2) eq 3">
135
                           <xsl:variable name="nested-class" select="$class/j[@in eq 'c'][@id eq $paths2[3]]"/>
136
                           <xsl:attribute name="to">nested-class</xsl:attribute>
137
                           <xsl:attribute name="found" select="if (exists($nested-class)) then 'yes'
138
                              else 'no'"/>
139
                        </xsl:when>
140
                        <xsl:otherwise>
141
                           <xsl:attribute name="to">class</xsl:attribute>
142
                           <xsl:attribute name="found" select="if (exists($class)) then 'yes'
143
                              else 'no'"/>
144
                        </xsl:otherwise>
145
                     </xsl:choose>
146
                  </xsl:otherwise>
147
               </xsl:choose>
148
            </tag>
149
         </xsl:if>
150
         
151
      </xsl:if>
152
      
153
   </xsl:template>
154
   
155
   
156
</xsl:stylesheet>
(1-1/15)