Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2008, 11:59 PM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default sequential transformations

I'm working on a content management system which pulls blog posts from MySQL and automagically turns them into XML data. This works. I've written XSLT code to sort the posts in descending or ascending order (determined by a parameter fed in via PHP) by date, then group the posts by date (i.e., posts written the same day appear under a common heading). This works.

Now I need to limit the number of posts displayed (current XSLT returns all posts). I'm fairly certain the recursive for-eaches used by the grouping code rule out doing this while grouping (although finding out I'm wrong about this would be a welcome discovery). So I think the only option is to apply the grouping template, then apply a second, post-limiting template to the result.

After reading quite a bit about result tree fragments, variables, and functions, I've yet to find any coherent sample XSLT that reprocessed results from another template. Perhaps part of the problem is that I don't know what to call what I'm trying to do and haven't found a Googleable term. Am I missing something glaringly obvious?

Here's my code:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="order" />
<xsl:param name="max" />

<xsl:template match="/">
  <html>
    <body>
        <xsl:apply-templates select="posts"/>
    </body>
  </html>
</xsl:template>

<xsl:key name="posts-by-date" match="post" use="date" />
<xsl:template match="posts">
  <xsl:for-each select="post[count(. | key('posts-by-date', date)[1]) = 1]">
    <xsl:sort select="timestamp" order="{$order}" />
    <h2><xsl:value-of select="date" /></h2>
    <xsl:for-each select="key('posts-by-date', date)">
      <xsl:sort select="timestamp" order="{$order}" />
        <h3><xsl:value-of select="title" /></h3>
        <xsl:value-of select="parent::node[count()]" />
        <xsl:value-of select="body" />
        (<xsl:value-of select="time" />)
    </xsl:for-each>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Thanks in advance. Note: I'm not limited to XSLT 1.0. Or at least I don't think so...






Similar Threads
Thread Thread Starter Forum Replies Last Post
Sequential numbering help gear1 Access 1 April 9th, 2007 06:31 AM
Sequential Numbers ricespn Access 5 February 17th, 2007 02:54 AM
XSLProcessor asynchronous transformations Vx BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 September 5th, 2006 12:41 PM
DTS transformations Amorous SQL Server DTS 0 January 18th, 2006 04:54 PM
XSL Transformations scottrudy VB.NET 0 July 4th, 2003 11:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.