Pavel Lepin <> wrote in
<fnrvab$sm0$>:
> graham.reeds <> wrote:
>> I am building a reports system. Several events can happen
>> in the space of an hour so over a long weekend there can
>> be quite a lot of events (hundreds). Therefore sending
>> everything as a single xml file will
>> take a long time. Also sending one report at a time
>> would take a long time for the roundtrip.
>>
>> What I was going to do was batch up a number of events
>> (say 10) and then make a request for the next 10. Simple
>> tests show that the first part of this works (I'm working
>> off the w3schools cd catalog example...
>>
>> with added javascript to hide all but 1 item at a time)
>> but I am unsure about the second part - specifically the
>> sending of data through the XSL file and having it append
>> to the original file. As far as I can see it will
>> overwrite the original html.
>>
>> Is this possible or am I better off sending individual
>> items through?
>
> Unless I misunderstood your description of the problem, it
> seems to me that the thing to do would be to use two
> separate transformations.
>
> The first one would aggregate your chunks into the XML
> document containing all relevant information (you would
> invoke this transformation on current version of aggregate
> document, providing, say, filenames of new chunks as
> parameters).
And here's how it would look in code:
pavel@debian:~/dev/xslt/aggr$ a aggregate.xsl
<xsl:stylesheet
version="1.0"
xmlns

sl="http://www.w3.org/1999/XSL/Transform"
xmlns:meta="http://example.org/meta-data">
<xsl

aram name="chunks"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="data">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:call-template name="process-chunks">
<xsl:with-param name="chunk-list"
select="concat($chunks,',')"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="process-chunks">
<xsl

aram name="chunk-list"/>
<xsl:variable name="car"
select="substring-before($chunk-list,',')"/>
<xsl:variable name="cdr"
select="substring-after($chunk-list,',')"/>
<xsl:call-template name="process-chunk">
<xsl:with-param name="chunk" select="$car"/>
</xsl:call-template>
<xsl:if test="$cdr">
<xsl:call-template name="process-chunks">
<xsl:with-param name="chunk-list" select="$cdr"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="process-chunk">
<xsl

aram name="chunk"/>
<xsl:if test="not(/data/item[@meta:chunk=$chunk])">
<xsl:apply-templates
select=
"
document(concat('chunk_',$chunk,'.xml'))
/data/item
"
mode="aggregate-chunk-items">
<xsl:with-param name="chunk-name" select="$chunk"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
<xsl:template match="data/item"
mode="aggregate-chunk-items">
<xsl

aram name="chunk-name"/>
<xsl:copy>
<xsl:attribute name="meta:chunk">
<xsl:value-of select="$chunk-name"/>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
pavel@debian:~/dev/xslt/aggr$ a data.xml
<data/>
pavel@debian:~/dev/xslt/aggr$ a chunk_1.xml
<data>
<item timestamp="127468743" value="13"/>
<item timestamp="127468746" value="12"/>
<item timestamp="127468749" value="16"/>
<item timestamp="127468750" value="9"/>
<item timestamp="127468755" value="10"/>
</data>
pavel@debian:~/dev/xslt/aggr$ xsltproc --stringparam chunks
1 aggregate.xsl data.xml >data_1.xml
pavel@debian:~/dev/xslt/aggr$ a data_1.xml
<?xml version="1.0"?>
<data><item xmlns:meta="http://example.org/meta-data"
meta:chunk="1" timestamp="127468743" value="13"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468746" value="12"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468749" value="16"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468750" value="9"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468755" value="10"/></data>
pavel@debian:~/dev/xslt/aggr$ a chunk_2.xml
<data>
<item timestamp="127468762" value="13"/>
<item timestamp="127468763" value="8"/>
<item timestamp="127468769" value="19"/>
</data>
pavel@debian:~/dev/xslt/aggr$ xsltproc --stringparam chunks
2 aggregate.xsl data_1.xml >data_2.xml
pavel@debian:~/dev/xslt/aggr$ a data_2.xml
<?xml version="1.0"?>
<data><item xmlns:meta="http://example.org/meta-data"
meta:chunk="1" timestamp="127468743" value="13"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468746" value="12"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468749" value="16"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468750" value="9"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468755" value="10"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="2"
timestamp="127468762" value="13"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="2"
timestamp="127468763" value="8"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="2"
timestamp="127468769" value="19"/></data>
pavel@debian:~/dev/xslt/aggr$ a chunk_3.xml
<data>
<item timestamp="127468770" value="21"/>
<item timestamp="127468771" value="7"/>
<item timestamp="127468781" value="18"/>
<item timestamp="127468783" value="9"/>
<item timestamp="127468785" value="2"/>
<item timestamp="127468795" value="11"/>
</data>
pavel@debian:~/dev/xslt/aggr$ xsltproc --stringparam chunks
1,2,3 aggregate.xsl data_2.xml >data_3.xml
pavel@debian:~/dev/xslt/aggr$ a data_3.xml
<?xml version="1.0"?>
<data><item xmlns:meta="http://example.org/meta-data"
meta:chunk="1" timestamp="127468743" value="13"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468746" value="12"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468749" value="16"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468750" value="9"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="1"
timestamp="127468755" value="10"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="2"
timestamp="127468762" value="13"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="2"
timestamp="127468763" value="8"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="2"
timestamp="127468769" value="19"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="3"
timestamp="127468770" value="21"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="3"
timestamp="127468771" value="7"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="3"
timestamp="127468781" value="18"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="3"
timestamp="127468783" value="9"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="3"
timestamp="127468785" value="2"/><item
xmlns:meta="http://example.org/meta-data" meta:chunk="3"
timestamp="127468795" value="11"/></data>
pavel@debian:~/dev/xslt/aggr$
--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.