[xsl] When to use text()

Subject: [xsl] When to use text()
From: "Heiko Niemann" <kontakt@xxxxxxxxxxxxxxxx>
Date: Fri, 21 Mar 2014 12:08:24 +0100

I noticed in my code that I sometimes use text() to select a text node and
sometimes I don't. I do understand that /foo is different to /foo/text()
if foo has mixed content. But if I have a simple source like


then I can't tell a difference for /box/item  and /box/item/text() using
value-of. I understand that value-of actually selects the value ('apple')
of the node (/box/item). Does that mean that using /box/item/text() is
wrong, unnecessary or just a matter of style or performance?

Same applies to using the if-element:

<xsl:if test="/box/item eq 'apple'">
<xsl:if test="/box/item/text() eq 'apple'"> ??

I noticed that I more often used text() in if-elements like this, probably
'to really make sure' to select a string to compare. Which was probably a
silly assumption whenever I wrote that code.

So this leaves the question: when actually use text()?


Current Thread