[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Processing node-sets in batches

Subject: Re: Processing node-sets in batches
From: Jeff Hooker <jeff@xxxxxxxxxxxx>
Date: Mon, 15 Mar 2010 13:37:36 -0700 (PDT)
Re:  Processing node-sets in batches
Hi all,

Couldn't get David's XSLT to work; I did a very sloppy job of
describing my environment and that's likely to blame. I thought the node-set
was basically a generic term used whenever you read set of nodes into a single
variable. I'm working with XSLT 2.0, and the following script achieved my
goal. Obviously it does not recreate valid docbook yet, but I'll do that next.
<xsl:templatematch="/">
<root>
<xsl:call-templatename="rackem"/>
</root>
</xsl:template>

<xsl:templatename="rackem">
<xsl:variablename="setsize">10</xsl:variable> <!-- the size of the sets I want
things broken into -->
<xsl:variablename="x"select="//testnode"></xsl:variable>
<xsl:for-eachselect="$x[(position() mod $setsize) = 1]">
<xsl:variablename="postion"select="position()"></xsl:variable><!-- the
for-each will divide the nodeset off into a number of sets; this is the set
number I'm working on now -->
<table>
<xsl:call-templatename="stackem">
<xsl:with-paramname="set"select="$position"/>
<xsl:with-paramname="total"select="$setsize"></xsl:with-param>
</xsl:call-template>
</table>
</xsl:for-each> 
</xsl:template>
<xsl:templatename="stackem">
<xsl:paramname="set">0</xsl:param>
<xsl:paramname="total">0</xsl:param>
<xsl:paramname="count">1</xsl:param>
<xsl:variablename="p"select="(($set - 1) * $total) + $count"></xsl:variable>
<xsl:variablename="x"select="//node"></xsl:variable>
<xsl:iftest="$count &lt;
($total + 1)">
<row>
<xsl:value-ofselect="$x[$p]"></xsl:value-of>
</row>
<xsl:call-templatename="stackem">
<xsl:with-paramname="set"select="$set"/>
<xsl:with-paramname="count"select="$count + 1"></xsl:with-param>
<xsl:with-paramname="total"select="$total"></xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>

I've likely used 30 or so more
lines than a clever person would need. Ah well. 
Jeff.



----- Original
Message ----
> From: David Carlisle <davidc@xxxxxxxxx>
> To:
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Cc: Jeff Hooker <jeff@xxxxxxxxxxxx>
> Sent:
Sun, March 7, 2010 4:04:06 PM
> Subject: Re:  Processing node-sets in
batches
> 
> On 07/03/2010 23:50, Jeff Hooker wrote:
>  so I'm trying to read
all 
> of the nodes into a node-set() and process them out into a series of
100-row 
> tables.

if you need the node-set() extension then probably you
have 
> copied the entire source into a result tree fragment, which might
account for 
> your
memory problems. hard to say. But that may not be what you
mean 
> (node-set() isn't valid xpath syntax so I'm having to guess)

I'm
assuming 
> you are using xslt 1 (you don't say) as xslt 2 doesn't have node
sets.

If 
> $x contains a node set then

<xsl:for-each select="$x[position()
mod 
> 100 = 1]">
<xsl:variable name="p" 
> select="position()"/>
<xsl:for-each select="$x[position()> $p * 
> 100][position()<= ($p+1) * 100]">
will process the nodes in batches 
> of a hundred

David

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.