xsl-list
[Top] [All Lists]

Re: [xsl] When to use text()

2014-03-21 06:37:34

On 21 Mar 2014, at 11:08, Heiko Niemann <kontakt(_at_)heiko-niemann(_dot_)de> 
wrote:

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>

In such content you should NOT use text(). If you do, your code will fail in 
the presence of comments such as

<item>appel<!--sic--> pie</item>

and it's good practice that comments should not affect the result of processing.

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


Only use it if you need to process the text node children and element children 
of a mixed-content element individually.

Michael Kay
Saxonica
--~------------------------------------------------------------------
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>