-
Notifications
You must be signed in to change notification settings - Fork 4
/
xslt-quality_namespaces.sch
54 lines (49 loc) · 3.18 KB
/
xslt-quality_namespaces.sch
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
<?xml version="1.0" encoding="UTF-8"?>
<pattern xmlns="http://purl.oclc.org/dsdl/schematron"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:xslq="https://github.com/mricaud/xsl-quality"
xml:lang="en"
id="xslt-quality_namespaces">
<xd:doc>
<xd:desc>
<xd:p>These rules are about namespace usage in XSLT</xd:p>
</xd:desc>
</xd:doc>
<rule context="xsl:template/@name | /*/xsl:variable/@name | /*/xsl:param/@name"
id="xslt-quality_namespaces_name">
<xd:doc>
<xd:desc xml:lang="en">Adding a namespace prefix at your global variables and parameters will make your XSLT more portable: it will avoid name conflict with other XSLT importing yours and vice versa.</xd:desc>
<xd:desc xml:lang="fr">Ajouter un préfixe de namespace sur vos variables et paramètres globaux rendra votre XSLT plus portable : cela évitera les conflit de nommage avec d'autres XSLT qui importerait la votre et vice versa</xd:desc>
</xd:doc>
<assert id="xslt-quality_ns-global-statements-need-prefix"
test="every $name in tokenize(., '\s+') satisfies matches($name, concat('^', $xslq:NCNAME.reg, ':'))"
role="warning">
<value-of select="local-name(parent::*)"/> <name/>="<value-of select="tokenize(., '\s+')[not(matches(., concat('^', $xslq:NCNAME.reg, ':')))]"/>" should be namespaces prefixed, so they don't generate conflict with imported XSLT (or when this xslt is imported)
</assert>
</rule>
<rule context="xsl:template/@mode"
id="xslt-quality_namespaces_mode">
<xd:doc>
<xd:desc xml:lang="en">Adding a namespace prefix at your template's mode will make your XSLT more portable: it will avoid name conflict with other XSLT importing yours and vice versa.</xd:desc>
<xd:desc xml:lang="fr">Ajouter un préfixe de namespace sur vos mode de template rendra votre XSLT plus portable : cela évitera les conflit de nommage avec d'autres XSLT qui importerait la votre et vice versa</xd:desc>
</xd:doc>
<assert id="xslt-quality_ns-mode-statements-need-prefix"
test="every $name in tokenize(., '\s+') satisfies matches($name, concat('^', $xslq:NCNAME.reg, ':'))"
role="warning">
<value-of select="local-name(parent::*)"/> @<name/> value "<value-of select="tokenize(., '\s+')[not(matches(., concat('^', $xslq:NCNAME.reg, ':')))]"/>" should be namespaces prefixed, so they don't generate conflict with imported XSLT (or when this xslt is imported)
</assert>
</rule>
<rule context="@match | @select"
id="xslt-quality_namespaces_xpath">
<xd:doc>
<xd:desc xml:lang="en">Avoid using "*:" in your xpath: it will slow your XSLT processor that will be obliged to check every local-names instead of just manipulating XML nodes.</xd:desc>
<xd:desc xml:lang="fr">Évitez d'utiliser "*:" dans vos xpath : cela va ralentir votre processeur XSLT qui sera forcé de vérifier le nom local des balises au lieur de manipuler des nœuds XML.</xd:desc>
</xd:doc>
<report id="xslt-quality_ns-do-not-use-wildcard-prefix"
test="contains(., '*:')">
Use a namespace prefix instead of *:
</report>
</rule>
</pattern>