473,769 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL sorting of results from recursive calls to document()?

Hello --

I am trying to use XSL to process Amazon wishlist data to sort the
results by type (Apparel, then Books, then DVDs, etc). Amazon's web
services chunk up results in multiple pages of fixed size, e.g. 55
items gets returned in 5 XML pages of 10 items and a 6th of 5 items.
Each page is returned from a distinct URL call with a PageNum
parameter.

I've been trying to adapt a technique described at http://www.xefer.com/amazon/wishlist
that shows how to iterate through such pages through recursive
document() calls and a document counter:

<xsl:template name="counter">
<xsl:param name="total"/>
<xsl:param name="page"/>

<xsl:variable name="lookup"
select="concat( $lookup, '&amp;ProductPa ge=', $page)

<xsl:if test="$page <= $total">
<xsl:apply-templates select="documen t($lookup)"/>
<xsl:call-template name="counter">
<xsl:with-param name="total" select="$total"/>
<xsl:with-param name="page" select="$page + 1"/>
</xsl:call-template>
</xsl:if>

</xsl:template>

This works, but I can't figure out how to sort the aggregate results.
Each document's nodes are processed separately before the next page is
retrieved. Is there a convention / idiom for how to handle sorting
when iterating via recursion across multiple document() calls?

Thanks,

Ramon
Oct 6 '08 #1
2 2493
felciano wrote:
I've been trying to adapt a technique described at http://www.xefer.com/amazon/wishlist
that shows how to iterate through such pages through recursive
document() calls and a document counter:

<xsl:template name="counter">
<xsl:param name="total"/>
<xsl:param name="page"/>

<xsl:variable name="lookup"
select="concat( $lookup, '&amp;ProductPa ge=', $page)

<xsl:if test="$page <= $total">
<xsl:apply-templates select="documen t($lookup)"/>
<xsl:call-template name="counter">
<xsl:with-param name="total" select="$total"/>
<xsl:with-param name="page" select="$page + 1"/>
</xsl:call-template>
</xsl:if>

</xsl:template>

This works, but I can't figure out how to sort the aggregate results.
Each document's nodes are processed separately before the next page is
retrieved. Is there a convention / idiom for how to handle sorting
when iterating via recursion across multiple document() calls?
Instead of using xsl:apply-templates select="documen t($lookup)" during
each template invocation you need to pass on those results the document
call returns. So give your template a third parameter

<xsl:template name="counter">
<xsl:param name="total"/>
<xsl:param name="page"/>
<xsl:param name="page-elements" select="/.."/>

<xsl:variable name="lookup"
select="concat( $lookup, '&amp;ProductPa ge=', $page)

<xsl:choose>
<xsl:when test="$page <= $total">
<xsl:call-template name="counter">
<xsl:with-param name="total" select="$total"/>
<xsl:with-param name="page" select="$page + 1"/>
<xsl:with-param name="page-elements" select="$page-elements |
document($looku p)/*"/>
</xsl:call-template>
</xsl:choose>
<xsl:otherwis e>
<xsl:apply-templates select="$page-elements">
<xsl:sort select="foo"/>
</xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose

</xsl:template>


--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 6 '08 #2
Very cool -- thank you for the quick response!

Ramon
Oct 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1939
by: carmen | last post by:
I'm using the code below to display the results in rows with the column header as hyperlinks that will sort the rows by colum heading. Is there a way to have the results sorted (as default) in reverse order so that the most recent are at the top of the page also when the user selects the Open Date or Status column headings, sort the data in reverse order . Code is below. Thanks <% ppl_ctr=0
9
3627
by: p0wer | last post by:
Let's suppose I have this sample document: <root> <entry id="1" <date>2003-08-03</date> <param_1>5</param_1> <param_2>10</param_2> </entry> <entry id="2"> ...
0
1686
by: Sparko | last post by:
My Xml is as follows; <root> <st id="1"> <rt id="1"> <cr id="1" ca_w="" ca_x="" ca_y="" ca_z="" other attribs> <ct some attribs> <te some attribs /> <te some attribs />
22
4168
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b) { return -1; } else
38
2778
by: Lasse Vågsæther Karlsen | last post by:
After working through a fair number of the challenges at www.mathschallenge.net, I noticed that some long-running functions can be helped *a lot* by caching their function results and retrieving from cache instead of calculating again. This means that often I can use a natural recursive implementation instead of unwinding the recursive calls to avoid big exponential running-times. Ok, so I thought, how about creating a decorator that...
8
3538
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At the moment the printed output is usually going to Word. It's turning into an unholy mess, because I'm having to prepare umpteen different Word templates, and the queries that drive them, depending on what events a course has.
1
10654
by: PhilB | last post by:
I have been having issues trying to merge sort a double linked list. (I would supply the code, but it is locked away on an inaccessable computer.) The list always results in an unsorted list, but no errors. I think I have tracked it down to the recursive functions locking on a node and then the node being moved during the sorting process. I used an example which sorts an array, so I had to make some guesses on interfacing it with a...
1
3528
by: jmdolinger | last post by:
Hi all, I'm a newbie to Atlas (and recently ASP.NET) after coming from a long Java background, also have done quite a bit with an Ajax.NET/ASP.NET 1.1 project, but it was basically all javascript, nothing really having to do with ASP.NET... I'm attempting to put together an application that consists of several GridView controls each bound to some xml data. Each table exists in its own update panel. The two effects I'm going for are:
13
2086
by: jm.suresh | last post by:
Hi, I have a program which literately finds the object that overlapping a point. The horizontal and vertical search are called recursively from inside each other. Is this way of implementation fill the stack space with the local variables inside each call. If this is not good, is there a better way to implement? Or python itself will understand that the calls happen in the last line, so local variables need not be pushed into the stack?
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.