Hello again,
Still debugging the upgrade to XSLT 2.0.  This one took some time to create 
a reduced stylesheet that still reproduced the error.  The XML instance file 
(probably irrelevant) is the same as my last post:
<?xml version="1.0" encoding="UTF-8"?>
<Test>"Hello" ≠ "World"</Test>
Using SaxonB-8.9j, I get the following error:
<<Error on line 42 of file:/C:/Test/Saxon/Test20.xsl:
XPTY0004: Cast does not allow an empty sequence
Transformation failed: Run-time errors were reported>>
with the following XSLT:
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output name="OutHTML" method="html" encoding="windows-1252"/>
   <xsl:param name="DocumentCode" select=" 'abc11111' "/>
   <xsl:param name="Flag1" select="boolean( true() or false() )"/> <!--  
force to true -->
   <xsl:param name="Flag2" select="boolean( number( substring( 
$DocumentCode , 6 , 1 ) ) )"/>
   <xsl:param name="Flag3" select="substring( $DocumentCode , 6 , 1 )"/>
   <xsl:variable name="FirstPass" as="document-node()">
       <xsl:document>
           <xsl:copy-of select="Test"/>
       </xsl:document>
   </xsl:variable>
   <xsl:template match="Test">
       <xsl:result-document href="test20.html" format="OutHTML">
           <xsl:apply-templates select="$FirstPass" mode="SomeMode"/>
       </xsl:result-document>
   </xsl:template>
   <xsl:template match="Test" mode="SomeMode">
       <html>
           <head>
               <title>test</title>
           </head>
           <body>
               <p><xsl:call-template name="SomeNamedTemplate"/></p>
           </body>
       </html>
   </xsl:template>
   <xsl:template name="SomeNamedTemplate">
       <xsl:variable name="SomeVariable1">
           <xsl:choose>
               <xsl:when test="$Flag3 = '1' and 
//SomeElement[not(ancestor::Foo)][not(contains(string(Bar),'$'))]">true</xsl:when>
               <xsl:when test="$Flag3 != '1' and 
//SomeElement[not(contains(string(Foo),'$'))]">true</xsl:when>
           </xsl:choose>
       </xsl:variable>
       <xsl:value-of select="$SomeVariable1"/>
   </xsl:template>
</xsl:stylesheet>
*However*, when I try to debug by adding an xsl:message within xsl:variable 
name="SomeVariable1", the error goes away (?!).  i.e. with this mod:
       <xsl:variable name="SomeVariable1">
           <!-- the xsl:message instruction below makes error go away! -->
           <xsl:message>Flag3: <xsl:value-of select="$Flag3"/>, Cond1: 
<xsl:value-of 
select="//SomeElement[not(ancestor::Foo)][not(contains(string(Bar),'$'))]"/>, 
Cond2: <xsl:value-of 
select="//SomeElement[not(contains(string(Foo),'$'))]"/></xsl:message>
           <xsl:choose>
               <xsl:when test="$Flag3 = '1' and 
//SomeElement[not(ancestor::Foo)][not(contains(string(Bar),'$'))]">true</xsl:when>
               <xsl:when test="$Flag3 != '1' and 
//SomeElement[not(contains(string(Foo),'$'))]">true</xsl:when>
           </xsl:choose>
       </xsl:variable>
I now get the following in the output, and the transformation continues to 
the end without any errors:
<<Flag3: 1, Cond1: , Cond2: >>
Any thoughts on what is going on here?
tia,
...sam