[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

When to use text()

Subject: When to use text()
From: "Heiko Niemann" <kontakt@xxxxxxxxxxxxxxxx>
Date: Fri, 21 Mar 2014 12:08:24 +0100
 When to use text()
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.