473,378 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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;ProductPage=', $page)

<xsl:if test="$page <= $total">
<xsl:apply-templates select="document($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 2468
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;ProductPage=', $page)

<xsl:if test="$page <= $total">
<xsl:apply-templates select="document($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="document($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;ProductPage=', $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($lookup)/*"/>
</xsl:call-template>
</xsl:choose>
<xsl:otherwise>
<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
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...
9
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
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
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)...
38
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...
8
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...
1
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...
1
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...
13
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.