XSLT name() function is evil and should be avoided just like GoTo.
For example, it is very bad to write
<xsl:apply-templates select="*[name()!='a:b']"/>
because it will exclude both of
<a:b/> <a:b xmlns:a="totallyDifferentNamespace"/>
the correct way to write above apply-templates is
<xsl:apply-templates select="*[not(self::a:b)]"/>
or in XSLT 2.0
<xsl:apply-templates select="* exclude a:b"/>
assuming xmlns:a="someSpecificNamespace"
Test code is attached below.
| Attachment | Size |
|---|---|
| xslt-evil-name.zip | 2.58 KB |
Comments
You should not be using
You should not be using name() function even if you have namespaces turned off.
Saxon (and perhaps some other processors) contain an optimization that translates XML qualified names into packed integer structures (see NamePool in Saxon).
So, using name() function bespoke potential problems also makes your XSLT code slow.
Post new comment