The root cause of this problem is that the optimizer isn't recognizing that the result of <xsl:number> depends on the context node, and it's therefore incorrectly moving it out of the <xsl:for-each>.
 
What happens next is somewhat bizarre, and is related to the fact that the body of the for-each instruction doesn't return a result: it exists solely for its side-effects. The empty() in the warning message is the type calculated for the xsl:message instruction, which in turn becomes the type of the entire xsl:for-each. Saxon is getting close to optimizing this entire template out of existence, having worked out that it never produces any principal output. Instead, it just produces this rather strange warning message.
 
Calling the document() function with a URL that's designed to have side-effects is not a particularly good idea (see http://www.w3.org/2001/tag/doc/whenToUseGet.html ). It's unpredictable whether and how often the document function will actually be called.
 
Using an xsl:variable whose select expression has side-effects compounds the problem: a variable will only be evaluated if its value is needed. Note in particular that the order of evaluating different variables is not well-defined.
 
If you want to write code that exists only for its side-effects, you have to adopt increasingly elaborate tricks to persuade the optimizer that you are producing real output. At present, you could fool the optimizer by writing say
 
<xsl:copy-of select="$sql-stat[position() + 1 = 0]"/>
 
within the <xsl:if> - but that won't necessarily work for ever.
 
Michael Kay
http://www.saxonica.com/

From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Roger Kovack
Sent: 17 January 2005 00:57
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Required item type of value of variable $0 is empty()... Saxon 8.2

Warning: Required item type of value of variable $0 is empty(); supplied value has item type empty(). The expression can succeed only if the supplied value is an empty sequence.; SystemID: xsl/wf/save-index.xsl; Line#: 101; Column#: -1 in "xsl/wf/wf-main.xsl"

I don't understand what this means and the actual line number is wrong. Line 101 is bolded below. The message is not presented when the <xsl:message> element is moved out of the <xsl:if>. I am definitely bewildered. And this is in the stylesheet that fails with Too many nested <xsl:call-template> calls error.

<xsl:template name="delete-index">
    <xsl:param name="task"/>
    <xsl:param name="doc-id"/>
    <xsl:for-each select="$task"> <!-- error line 101 -->
        <xsl:variable name="sql">
        delete from tasks where
        docId='<xsl:value-of select="$doc-id"/>'
        and path='<xsl:number count="task" level="multiple" format="1."/>'
        </xsl:variable>
        <xsl:variable name="encoded-sql" select="escape-uri($sql, false())"/>
        <xsl:variable name="sql-stat" select="document(
            concat('http://localhost/xsl/sqlps?sql=', $encoded-sql))"/>
        <xsl:if test="$sql-stat/sqltoxml-error">
            <xsl:message>Task index update error: <xsl:copy-of select="$sql-stat"/></xsl:message>
        </xsl:if>
    </xsl:for-each>
</xsl:template>

Thanks again for your attention. I really appreciate it.

Roger Kovack
------------------------------------------------------- The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt _______________________________________________ saxon-help mailing list saxon-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/saxon-help