Support #5942


Handling of elements without text() child elements changed between 9.8.x.x and 9.9.x.x

Added by Marijn Sanderse over 1 year ago. Updated over 1 year ago.

Start date:
Due date:
% Done:


Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:


If I have an XML document

* <EmptyDoc />*

and I perform the following test

*<xsl:if test="EmptyDoc/text()=''">*

that test is TRUE in 9.8.x.x but it is FALSE in 9.9.x.x and 11.5

I can see the reasoning behind the change (there is no text node so it cannot be equal to "") and I can see the impossibility in you changing this back after so much time but it is a bit of a headache for me given the 300+ services I am maintaining that could all suffer from this when I upgrade to a more current Saxon version.

Are there any pointers you could give me about how to handle this? Like:

  • is there I flag I can provide that reinstates previous behaviour?
  • what kind of statements also to look for?

Any help is really appreciated, thanks in advance

SaxonEE on Java


saxon-textnode.tgz (2.66 KB) saxon-textnode.tgz problem reproducer Marijn Sanderse, 2023-03-28 15:19
Actions #1

Updated by Marijn Sanderse over 1 year ago

That xml document is

Actions #2

Updated by Marijn Sanderse over 1 year ago

  <EmptyDoc />
Actions #3

Updated by Michael Kay over 1 year ago

  • Description updated (diff)
Actions #4

Updated by Michael Kay over 1 year ago

If what you're saying is correct, then that would most definitely be a bug in 9.8. It seems a rather unlikely one, and certainly with a quick test using Saxon-HE, I can't reproduce it. I suspect something more subtle is going on. Perhaps you could put together a repro that demonstrates the problem, a test cases that produces different results under different releases?

One possible explanation might be, for example, that the input is supplied as a programmatically-constructed DOM tree in which there is a zero-length text node. That's something that the XDM data model used by XPath doesn't allow, and over time we might have become better at "repairing" it to be conformant. That's a wild guess, but I suspect that getting to the bottom of it is going to involve some set of specific circumstances like that.

Actions #5

Updated by Marijn Sanderse over 1 year ago

Constructing the repro taught me that the "problem" is indeed a bit different than I initially thought: in 9.8 and before it was possible to cast a string value to a node() and then get its value from the text() node. In that scenario $var/text()='' did return true and now return false.

See testTextNodeFromEmpty2() in MyTransformerTest in the attached reproducer.

That is not something I expect or hope you will solve so I will be cleaning up my xslt's

Actions #6

Updated by Michael Kay over 1 year ago

Thanks. I haven't been able to track down a specific issue here, but from what you're saying it looks as if Saxon 9.8 for

<xsl:variable name="x">
  <xsl:value-of select="''"/>

was incorrectly producing a document node containing a single empty text node child, rather than a document node with no children.

Actions #7

Updated by Michael Kay over 1 year ago

I've confirmed that the bug was present in but was fixed in

Unfortunately, that hasn't enabled me to locate the specific bug issue.

But out of insatiable curiosity I traced the execution in a 9.8 build, and found it was bug #4246.

Bug #4246 is documented as being fixed in rather than - that's because we found that only contained a partial fix, it didn't solve it in the case of bytecode generation, and the full fix only came in

Not that this information is useful to anyone, I'm afraid.

Actions #8

Updated by Michael Kay over 1 year ago

  • Status changed from New to Closed

Please register to edit this issue

Also available in: Atom PDF