What's exactly the difference between ['#'] and [.='#']? Is there any difference at all?
In e.g. the following expressions:
<xsl:template match="a/@href[.='#']">...</xsl:template>
<xsl:template match="a/@href['#']">...</xsl:template>
A predicate filters, if the contained expression is not true. [.='#'] tests if the string content of the current context (.) equals #, thus the first template would return all @href attributes for links like <a href="#">...</a>.
The second template does not contain a boolean statement, and it also isn't numerical (so it would be a positional test). It will be evaluated as given by the boolean function:
Function:
boolean boolean(object)The boolean function converts its argument to a boolean as follows:
- a number is true if and only if it is neither positive or negative zero nor NaN
- a node-set is true if and only if it is non-empty
- a string is true if and only if its length is non-zero
- an object of a type other than the four basic types is converted to a boolean in a way that is dependent on that type
Here, we have a non-empty string with effective boolean value true, thus the predicate in your second template will never filter anything.
A predicate like in //a[@href] on the other hand would filter for all links containing an @href attribute (here, we filter for a node-set).