← Prev in month ← Prev in thread

How can the content of a leaf element be multiple text nodes?

From
Roger L Costello <>
To
"" <>
Date
2022-02-11T15:12:44Z
ID
<>
Thread
How can the content of a leaf element be multiple text nodes?
Hi Folks,

Okay, I'm confused.

I thought that a leaf element can have either zero or one text node. 

Apparently a leaf element can have 0, 1, 2, 3, 4, 5, 6, ... text nodes! 

For example, how many text nodes does this leaf element have?

<Test>abc<!-- blah -->def</Test>

Answer: It has two text nodes: 

	text()[1] and text()[2]

How do I know this? Well, I executed this XPath:

	Test/text()[1]

which resulted in this output:

	abc

and this XPath:

	Test/text()[2]

resulted in this output:

	def
 
To confirm that there are indeed two text nodes within the <Test> element, I used XPath to count the number of text nodes:

	count(Test/text())

That produced this output:

	2

In fact, the text node containing "def" *follows* the text node containing "abc", as this XPath shows:

	Test/text()[1]/following::text()

That gave this output:

	def

Interesting!

But the really interesting thing is that if I create an XPath to answer this question: What is the text in the <Test> element?

	Test/text()

Shockingly, I get this output:

	abcdef

Huh???

The previous tests determined that there are two separate text nodes, so how can there now be only one text node?

I am confused.

/Roger
← Prev in month ← Prev in thread