Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - XSL sorting of results from recursive calls to document()? >Thread Next - Re: XSL sorting of results from recursive calls to document()? Re: XSL sorting of results from recursive calls to document()?To: NULL Date: 10/6/2008 2:35:00 PM
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, '&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, '&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/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
