Skip to content

Commit 864875d

Browse files
committed
fix: error when running on itself
1 parent 323d93a commit 864875d

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

XSLTLint.xslt

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<!--
33
## XSLTLint.xslt
4-
4+
55
Tests an XSLT file for some common (and frankly, embarrassing) errors.
66
-->
77
<!DOCTYPE xsl:stylesheet [
@@ -37,25 +37,25 @@
3737
</xsl:variable>
3838
<xsl:variable name="ns-prefixes" select="make:node-set($ns-prefixes-RTF)/ns" />
3939
<xsl:variable name="no-go-chars" select="concat($apos, $quot, '/(;)=&amp;&lt;&gt;$#€%!?+^`´@*\')" />
40-
40+
4141
<xsl:variable name="selectAttrs" select="//xsl:*/@select" />
4242
<xsl:variable name="testAttrs" select="//xsl:*/@test" />
4343
<xsl:variable name="exprAttrs" select="$selectAttrs | $testAttrs" />
44-
44+
4545
<!-- Grab any includes/imports -->
4646
<xsl:variable name="includes" select="/xsl:stylesheet/*[self::xsl:include or self::xsl:import]" />
47-
47+
4848
<xsl:template match="/">
4949
<!--
5050
Start by testing some special cases
5151
-->
52-
52+
5353
<!-- Undeclared namespaces -->
5454
<xsl:apply-templates select="$selectAttrs[substring-before(., ':')][not(substring-before(., '::'))]" mode="undeclared-ns-prefix" />
5555

5656
<!-- Grab a reference inside this doc -->
5757
<xsl:variable name="excluded-prefixes" select="xsl:stylesheet/@exclude-result-prefixes" />
58-
58+
5959
<!-- Missing prefixes in `exclude-result-prefixes` attribute -->
6060
<xsl:for-each select="$ns-prefixes">
6161
<xsl:variable name="prefix" select="@prefix" />
@@ -65,25 +65,25 @@
6565
</xsl:call-template>
6666
</xsl:if>
6767
</xsl:for-each>
68-
68+
6969
<!-- Undeclared variables/params -->
7070
<xsl:apply-templates select="$exprAttrs[starts-with(., '$')]" mode="undeclared-variable" />
71-
71+
7272
<!-- Undeclared keys -->
7373
<xsl:apply-templates select="$exprAttrs[contains(., &KEY_BEGIN;)]" mode="undeclared-key" />
74-
74+
7575
<!-- Illegal AVTs -->
7676
<xsl:apply-templates select="$selectAttrs[contains(., '{') and contains(., '}')]" mode="illegal-avt" />
77-
77+
7878
<!-- Now process the various elements in the stylesheet -->
7979
<xsl:apply-templates select="*" />
80-
80+
8181
</xsl:template>
82-
82+
8383
<xsl:template match="*">
8484
<xsl:apply-templates select="*" />
8585
</xsl:template>
86-
86+
8787
<!--
8888
Checks for variable declarations including the dollar-sign (it happens)
8989
-->
@@ -118,28 +118,28 @@
118118
</xsl:otherwise>
119119
</xsl:choose>
120120
</xsl:if>
121-
121+
122122
<xsl:if test="key('matchTemplatesIndex', $template)">
123123
<xsl:call-template name="error">
124124
<xsl:with-param name="message" select="'There is however, a *match template* defined with this name, so looks like a #snippetfail'" />
125125
<xsl:with-param name="linefeed" select="false()" />
126126
</xsl:call-template>
127127
</xsl:if>
128-
128+
129129
<!-- Check for misplaced `<xsl:param>` (where it should have been `<xsl:with-param>`) -->
130130
<xsl:if test="xsl:param">
131131
<xsl:call-template name="error">
132132
<xsl:with-param name="message" select="concat('A call to &quot;', $template, '&quot; contains misplaced `&lt;xsl:param&gt;` (you probably mean `&lt;xsl:with-param&gt;`).')" />
133133
</xsl:call-template>
134134
</xsl:if>
135135
</xsl:template>
136-
136+
137137
<!--
138138
Test if we accidentally forgot to add a mode to a template
139139
-->
140140
<xsl:template match="xsl:apply-templates">
141141
<xsl:variable name="mode" select="@mode" />
142-
142+
143143
<xsl:if test="normalize-space($mode) and not(key('modedTemplatesIndex', $mode))">
144144
<xsl:variable name="message" select="concat('An &lt;xsl:apply-templates /&gt; instruction use the mode ', $apos, $mode, $apos, ' but no templates are defined in that mode. Did you forget to add it?')" />
145145
<xsl:choose>
@@ -158,17 +158,17 @@
158158
</xsl:choose>
159159
</xsl:if>
160160
</xsl:template>
161-
161+
162162
<!--
163163
Check for namespace-prefixes that haven't been declared
164164
-->
165165
<xsl:template match="@select" mode="undeclared-ns-prefix">
166166
<xsl:variable name="prefix" select="substring-before(., ':')" />
167-
167+
168168
<!--
169169
Ideally, this should obviously be "properly" parsed, but we can eliminate a lot of false positives
170170
just by doing a little filtering - throw away all characters that shouldn't be used in a prefix
171-
and check if the string is still (probably) the same...
171+
and check if the string is still (probably) the same...
172172
-->
173173
<xsl:if test="string-length($prefix) = string-length(translate($prefix, $no-go-chars, ''))">
174174
<!-- Go through the declared prefixes to find a match -->
@@ -178,9 +178,9 @@
178178
</xsl:call-template>
179179
</xsl:if>
180180
</xsl:if>
181-
181+
182182
</xsl:template>
183-
183+
184184
<!--
185185
Check for undeclared variables
186186
-->
@@ -194,14 +194,14 @@
194194
</xsl:if>
195195
</xsl:if>
196196
</xsl:template>
197-
197+
198198
<!--
199199
Check for missing `xsl:key` declaration
200200
-->
201201
<xsl:template match="@select | @test" mode="undeclared-key">
202202
<xsl:variable name="keyName" select="substring-before(substring(substring-after(., &KEY_BEGIN;), 2), $apos)" />
203203
<xsl:variable name="message" select="concat('A `key()` function used an undeclared key name (', $keyName, ').')" />
204-
<xsl:if test="not(key('keyNamesIndex', $keyName))">
204+
<xsl:if test="normalize-space($keyName) and not(key('keyNamesIndex', $keyName))">
205205
<xsl:choose>
206206
<xsl:when test="$includes">
207207
<xsl:if test="not(document($includes/@href, /)//xsl:key[@name = $keyName])">
@@ -224,7 +224,7 @@
224224
<xsl:with-param name="message" select="concat('An AVT (Attribute Value Template) was used in a `@select` attribute (', $quot, ., $quot, ').')" />
225225
</xsl:call-template>
226226
</xsl:template>
227-
227+
228228
<!--
229229
Output template for generating the error messages
230230
-->
@@ -234,5 +234,5 @@
234234
<xsl:if test="$linefeed"><xsl:value-of select="$LF" /></xsl:if>
235235
<xsl:value-of select="$message" />
236236
</xsl:template>
237-
237+
238238
</xsl:stylesheet>

0 commit comments

Comments
 (0)