xsl-list
[Top] [All Lists]

[xsl] When to use text()

2014-03-21 06:08:41
Hi,

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

<box>
  <item>apple</item>
</box>

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'">
or
<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()?


Regards,
Heiko




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>