Re: How can I not include empty elements?

On Mon, May 19 2008 00:15:34 +0100, levon@altjira.co.uk wrote:
> In reply to David A's comments, he has made a slight mistake in his
> reply when he says the text() function returns nodes that have
> text. This function will actually return to text node. You would

We are straying from jlr's original post, but David's example was:

   <xsl:for-each select="//artits/artist[text()]">

and his description was "The text() function just selects any node that
has text content."

Strictly speaking, text() is a node test [1], not a function.  The XPath
1.0 definition is:

   The node test text() is true for any text node. For example,
   child::text() will select the text node children of the context node.

The use of text() in '[text()]' means the predicate [2] filters what
would otherwise be selected so that it includes only nodes that have
text node children (since '[text()]' is abbreviated syntax [3] for
'[child::text()]').

So if I were to describe David's select expression*, I'd say the
expression selects only artist elements that have text node children.

Regards,


Tony Graham                         Tony.Graham@MenteithConsulting.com
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2


*  W.r.t. the provided XML and after fixing typos in the XSLT

[1] http://www.w3.org/TR/xpath#node-tests
[2] http://www.w3.org/TR/xpath#predicates
[3] http://www.w3.org/TR/xpath#path-abbrev

Received on Thursday, 22 May 2008 12:16:07 UTC