Your problem is that you are combining several problems in one and are
trying to solve them at once.
This can be solved by addressing each problem individually and then
combining the solutions. Probably a multi-pass solution will be one of the
easiest possible.
However, the problem in your code is not at all the sorting.
It seems to me that your date arithmetic is not OK.
In particular:
[color=blue]
> <xsl:apply-templates select="current()[number( concat(
> substring(Date,1,4),substring(Date,6,2),substring( Date,9,2) ) ) >=
> ($date - $new_days)]"/>
> <xsl:apply-templates select="current()[number( concat(
> substring(Date,1,4),substring(Date,6,2),substring( Date,9,2) ) ) <
> ($date - $new_days)]"/>[/color]
the above calculation of "new" and "old" links will not work correctly in
most of the cases.
So, I would recommend that you try to split the task into sub-problems,
which are more realistic and manageable and then you have greater chances to
succeed.
You may find a dates/time library of templates useful. One such library is
the datetime_lib.xsl library, which comes with the XSelerator and can be
downloaded with the trial version of the product.
=====
Cheers,
Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"p0wer" <p0wer@bojko_krakow_pl> wrote in message
news:3f5ee53c@news.vogel.pl...[color=blue][color=green]
> > Can you provide a complete (but the smallest possible) example --
> > source.xml, your transformation, the result and how it doesn't meet
> > your expectations.[/color]
>
> It is a basic link list built with XML:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <LinkList>
> <Entries>
> <Entry id="1">
> <SomeTags/>
> <Date>2003-08-01</Date>
> <SomeTags/>
> <LinkData>
> <Hits count="10"/>
> <Rates>
> <rate>6</rate>
> <rate>4</rate>
> </Rates>
> <SomeTags/>
> </LinkData>
> </Entry>
> <Entry id="2">
> <SomeTags/>
> <Date>2003-09-10</Date>
> <SomeTags/>
> <LinkData>
> <Hits count="5"/>
> <Rates>
> <rate>9</rate>
> <rate>1</rate>
> </Rates>
> <SomeTags/>
> </LinkData>
> </Entry>
> </Entries>
> <SomeTags/>
> </LinkList>
>
> What I want is to simply generate a list, where:
> - newest entries (let's say not older than 30 days) are placed on the top[/color]
of[color=blue]
> the list
> - newest entries and the rest are sorted separately
> - sorting order of each group is Hits-Rate (which is a simple average of[/color]
all[color=blue]
> rates)
> - each output page displays a defined number of links (passed as param by
> PHP)
>
> Seems like I can't get it the recursive way because XSLT does not allow to
> reassign variable values. I have managed though to make it sort the[/color]
entries[color=blue]
> in the top-level approach, that means I have first sorted them according[/color]
to[color=blue]
> Hits, then Rate and Date coming last. But trying to output all the new
> entries first, and then the rest, still maintaining the order and limiting
> the number of links per page seems too hard for me.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="html" encoding="iso8859-1" indent="yes"
> standalone="yes"/>
>
> <!-- Variables used in document -->
> <xsl:param name="style_css"/>
> <xsl:param name="start_id">0</xsl:param>
> <xsl:param name="end_id">0</xsl:param>
> <xsl:param name="date"/>
> <xsl:param name="new_days">30</xsl:param>
>
> <xsl:template match="/">
> <html>
> <head>
> <link rel="stylesheet" href="{$style_css}"/>
> </head>
> <body scroll="auto">
> <table width="100%" height="100%" border="0" cellpadding="3"
> cellspacing="0">
> <tbody>
> <tr>
> <td height="100%" align="center" valign="top">
>
> <xsl:call-template name="date_check"/>
>
> </td>
> </tr>
> </tbody>
> </table>
> </body>
> </html>
> </xsl:template>
>
> <xsl:template name="date_check">
> <xsl:param name="new">0</xsl:param>
> <xsl:for-each select="/LinkList/Entries/Entry">
> <xsl:sort select="LinkData/Hits/@count" order="descending"/>
> <xsl:sort select="sum(LinkData/Rates/rate) div[/color]
count(LinkData/Rates/rate)"[color=blue]
> order="descending"/>
> <xsl:sort select="Date" order="descending"/>
> <xsl:value-of select="position()"/>
> <xsl:if test="$end_id = 0 or (position() >= $start_id and position()
> <= $end_id)">
> <xsl:apply-templates select="current()[number( concat(
> substring(Date,1,4),substring(Date,6,2),substring( Date,9,2) ) ) >=
> ($date - $new_days)]"/>
> <xsl:apply-templates select="current()[number( concat(
> substring(Date,1,4),substring(Date,6,2),substring( Date,9,2) ) ) <
> ($date - $new_days)]"/>
> </xsl:if>
> </xsl:for-each>
> </xsl:template>
>
> <xsl:template match="Entry">
> <xsl:variable name="entry_date">
> <xsl:value-of select="number( concat(
> substring(Date,1,4),substring(Date,6,2),substring( Date,9,2) ) )"/>
> </xsl:variable>
>
> <!-- This is just simple display - trimmed down -->
> <table width="100%" border="0" cellpadding="0" cellspacing="0"
> style="border:none">
> <tbody>
> <tr>
> <td align="left" valign="middle">
> <a>
> <xsl:attribute name="href">
> <xsl:text>?action=view&id=</xsl:text>
> <xsl:value-of select="@id"/>
> </xsl:attribute>
> <xsl:value-of select="Title"/>
> </a>
> <xsl:if test="$entry_date >= ($date - 30)">
> <span class="red">NEW!</span>
> </xsl:if>
> </td
> <td align="center" width="80" height="40">
> <div class="red">
> <xsl:value-of select="LinkData/Hits/@count"/>
> </div>
> <span class="small">
> <br/>(<xsl:value-of select="Date"/>)
> </span>
> </td>
> <td align="center" width="40">
> <span class="red">
>
> <xsl:value-of select="format-number( ( sum(LinkData/Rates/rate) ) div
> ( count(LinkData/Rates/rate) ),'0.0')"/>
>
> </span>
> </td>
> </tr>
> </tbody>
> </table>
> </xsl:template>
>
> Let's say we have this data:
> - id=1 & id=2 are old entries
> - id=3 & id=4 are new entries
> - id=2 has hits=2
> - id=3 has rate=2
> - 2 links per page
> After sorting the order is 2-3-4-1, which is correct. But right now I get[/color]
it[color=blue]
> only this way. What I need is 3-4-2-1... The two entries for[/color]
apply-templates[color=blue]
> were used for some conditional choices, but it didn't work out exactly[/color]
what[color=blue]
> was expected. The selects are working, but now I need to put them[/color]
somewhere[color=blue]
> else to group the nodes.
>
>
> --
>
> __ .: Radoslaw Loboda :. | Cool stuff !!!
> (oo)
rloboda@bojko.krakow.pl | --------------------
> / \/ \ |
www.tigerhomes.org
> `V__V' |
www.suncam.tv
>
>
>[/color]