XSLT fn:name() is evil

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.

AttachmentSize
xslt-evil-name.zip2.58 KB

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.

More information about formatting options