In both the supplied stylesheets, document('GradeBook.xml') is only called once, so discard-document is not going to affect it one way or the other.

However, if you do this:

<xsl:for-each select="//teacher">
            <xsl:variable name="StudentGrades"
                select="saxon:discard-document(document(@GradeBookFile))"/>

then the grade book will be read more than once if two teachers have the same GradeBookFile.

One of your stylesheets does this:

        <xsl:variable name="StudentGrades">
            <xsl:for-each select="saxon:discard-document(document('GradeBook.xml'))">
                <xsl:copy-of select="."/>
            </xsl:for-each>
        </xsl:variable>

and the other does this:

        <xsl:variable name="StudentGrades" select="saxon:discard-document(document('GradeBook.xml'))"/>

Creating a copy of the document (as in the first example) is clearly unnecessary and should therefore be avoided. The cost isn't as extreme as it appears at first sight, because Saxon will create a "virtual copy" (the two copies of the tree have different identity but share the same memory); but there are still extra costs.

Michael Kay
Saxonica



On 24/06/2012 17:09, David Rudel wrote:
Michael,
You are correct. This is the test I conducted and reported back that I did not see any difference in a clean-room test. That is when I reported back that, when doing my work on my real project, I must have made some other change at the same time that I switched to push processing.

I provided these scripts to illustrate how I was using saxon:discard-document. It is my contention that using this kind of setup does not generally lead to the document being re-read/re-parsed multiple times. And I believe that is true regardless of whether the variable is set up as a temporary document or whether it is just created with:

<xsl:variable name="data" select="saxon:discard-document(document(@GradeBookFile)/>



Sorry for the confusion regarding the purpose of the test scripts. I was just trying to spell out how I was using the command in conjunction with keys, with the document node being passed into the child nodes and my inference that in this particular setup the document did not appear to being read more than once.

-David

On Sun, Jun 24, 2012 at 5:54 PM, Michael Kay <mike@saxonica.com> wrote:
At first sight I'm not seeing a significant difference between the performance of the pull and push versions of the stylesheet. What figures are you seeing, and how are you obtaining them?

Michael Kay
Saxonica


On 24/06/2012 09:24, David Rudel wrote:
Michael,
I wrote up a simple test script that uses discard-document() and keys in a way similar to how I use them in my work.
This example is just meant to test the passing of the nodes into the child templates. In my actual script the work done in the parent template is more substantial.
I've attached sample source/ancillary files if you want to see their structure. The attached source (activities.xml) only has one <teacher>, but in the equivalent file in my script might have hundreds, each with her own separate gradebook file.

The basic idea behind this fake test is that a group of teachers gives different activities (drill versus reading) on the first 90 days of the year. Some days giving one, some the other, some both (in either order). The teacher also keeps a gradebook that tracks what each student's gradeband is on various dates. The script below works through the activities of each teacher and, for each student, indicates what gradeband the student was next assessed as being in. It also converts "pages read" into minutes for those cases where the activity was reading.

In my actual use case, I might call 1000 teachers, each teacher with her own "gradebook" file that I need to use when evaluating students from that teacher. The the file is discarded when I move on to the next teacher.

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:udf="user-defined"
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:err="http://www.w3.org/2005/xqt-errors"
    xmlns:math="http://exslt.org/math" xmlns:saxon="http://saxon.sf.net/"
    xmlns:exsl="http://exslt.org/common" xmlns:date="http://exslt.org/dates-and-times"
    exclude-result-prefixes="xs xdt udf saxon math fn err exsl date">
    <xsl:key name="gradeKey" match="students/student/change" use="../@number"/>

    <xsl:template match="/">
        <xsl:for-each select="//teacher">
            <xsl:variable name="StudentGrades"
                select="saxon:discard-document(document(@GradeBookFile))"/>

            <activities>
                <xsl:for-each select="activities/day">
                    <day date="{@date}">
                        <xsl:apply-templates>
                            <xsl:with-param name="StudentGrades" select="$StudentGrades"/>
                        </xsl:apply-templates>
                    </day>
                </xsl:for-each>
            </activities>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="reading">
        <xsl:param name="StudentGrades"/>
        <activity type="reading">
            <xsl:for-each select="student">
                <student number="{@number}" minutes="{3*xs:integer(@pages)}"
                    next_gradeband="{key('gradeKey',@number,$StudentGrades)[xs:date(@date) gt xs:date(current()/../../@date)][1]/@gradeband}"/>
                <xsl:text>
    </xsl:text>
            </xsl:for-each>
        </activity>
    </xsl:template>

    <xsl:template match="drill">
        <xsl:param name="StudentGrades"/>
        <activity type="drill">
            <xsl:for-each select="student">
                <student number="{@number}" minutes="{xs:integer(@minutes)}"
                    next_gradeband="{key('gradeKey',@number,$StudentGrades)[xs:date(@date) gt xs:date(current()/../../@date)][1]/@gradeband}"/>
                <xsl:text>
    </xsl:text>
            </xsl:for-each>
        </activity>
    </xsl:template>

</xsl:stylesheet>

On Sun, Jun 24, 2012 at 1:03 AM, Michael Kay <mike@saxonica.com> wrote:

>
> Just to be clear, I only had one saxon:discard-document call in the
> program. As described in my previous email, I created a variable:
>
> <xsl:variable name="ïnfo"
> select=''saxon:discard-document(document(file))''>
>
> and then I used the variable $info in various places.

It's very difficult to be definitive about the effect this will have
when we can only see tiny fragments of your code. (It's not even clear
if this variable is local or global...)

Just to explain what discard-document() does:

Saxon maintains (owned by the Transformer/Controller) a table that maps
document URIs to document nodes. When you call the document() function,
Saxon looks to see if the URI is in this table, and if it is, it returns
the corresponding document node. If it isn't, it reads and parses the
resource found at that URI. The effect of saxon:discard-document() is to
remove the entry for a document from this mapping table. (Of course, if
a document is referenced from this table then the garbage collector will
hold the document in memory; if it is not referenced from the table then
it becomes eligible for garbage collection. It won't be garbage
collected if it's referenced from a global variable; but it will still
be absent from the table in the event that another call on document()
uses the same URI again.)

Michael Kay
Saxonica

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help 

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help