Re: Sorting Problem

Discussion in 'XML' started by Dimitre Novatchev, Jul 21, 2003.

  1. Use:

    <xsl:apply-templates select="$nodeset">
    <xsl:sort select="rank"/>

    <xsl:if test="position() >= 1 and position() &lt; 11">
    <!-- Process the current node here -->
    </xsl:if>
    </xsl:apply-templates>


    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL

    "Xeon" <> wrote in message
    news:...
    > Hi,
    >
    > Say I have 100 nodes in $nodeset. I want to display only a sorted
    > portion of it (say 10) at a time. One obvious way is :
    >
    > <xsl:apply-templates select="$nodeset[position()&gt;=1 and
    > position()&lt;=1]">
    > <xsl:sort select="rank"/>
    > </xsl:apply-templates>
    >
    > The problem is the above codes only sort the 1st 10 nodes before
    > they're processed. What I need is the nodes are sorted globally (all
    > 100 nodes sorted) before 10 of them is actually processed for display.
    > How do I do this?
    >
    > I've toyed with the idea of using dummy templates like this, assuming
    > the nodes in the $nodeset are of type 'item':
    >
    > ...
    > <xsl:apply-templates select="$nodeset" mode="presort">
    > <xsl:sort select="rank"/>
    > </xsl:apply-templates>
    > ...
    >
    > <xsl:template match="item" mode="presort">
    > <xsl:apply=templates select="self::node()[position()&gt;=1 and
    > position()&lt;=10]" mode="culled"/>
    > </xsl:template>
    >
    > <xsl:template match="item" mode="culled">
    > <!-- some actual processing -->
    > </xsl:template>
    >
    > The code works but displayed all the 100 nodes. I cannot control how
    > many nodes to display at a time (the predicate in
    > self::node()[position()&gt;=1 and position()&lt;=10] do not work).
    >
    > Any help appreciated
    > TIA
    Dimitre Novatchev, Jul 21, 2003
    #1
    1. Advertising

  2. Dimitre Novatchev

    Xeon Guest

    "Dimitre Novatchev" <> wrote in message news:<bfhk75$f1btb$-berlin.de>...
    > Use:
    >
    > <xsl:apply-templates select="$nodeset">
    > <xsl:sort select="rank"/>
    >
    > <xsl:if test="position() >= 1 and position() &lt; 11">
    > <!-- Process the current node here -->
    > </xsl:if>
    > </xsl:apply-templates>
    >

    The problem with this approach is sablotron wouldn't accept <xsl:if>
    or <xsl:choose> inside <xsl:apply-templates> or <xsl:call-template>.

    TIA
    Xeon, Jul 23, 2003
    #2
    1. Advertising

  3. Then it's completely broken -- are you sure your code is OK?


    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL


    "Xeon" <> wrote in message
    news:...
    > "Dimitre Novatchev" <> wrote in message

    news:<bfhk75$f1btb$-berlin.de>...
    > > Use:
    > >
    > > <xsl:apply-templates select="$nodeset">
    > > <xsl:sort select="rank"/>
    > >
    > > <xsl:if test="position() >= 1 and position() &lt; 11">
    > > <!-- Process the current node here -->
    > > </xsl:if>
    > > </xsl:apply-templates>
    > >

    > The problem with this approach is sablotron wouldn't accept <xsl:if>
    > or <xsl:choose> inside <xsl:apply-templates> or <xsl:call-template>.
    >
    > TIA
    Dimitre Novatchev, Jul 23, 2003
    #3
  4. (Xeon) wrote in message news:<>...
    > "Dimitre Novatchev" <> wrote in message news:<bfhk75$f1btb$-berlin.de>...
    > > Use:
    > >
    > > <xsl:apply-templates select="$nodeset">
    > > <xsl:sort select="rank"/>
    > >
    > > <xsl:if test="position() >= 1 and position() &lt; 11">
    > > <!-- Process the current node here -->
    > > </xsl:if>
    > > </xsl:apply-templates>
    > >

    > The problem with this approach is sablotron wouldn't accept <xsl:if>
    > or <xsl:choose> inside <xsl:apply-templates> or <xsl:call-template>.



    Yes, I am so sleepy morning-time ...

    You can either use the above code changed into an xsl:for-each like
    this:

    <xsl:for-each select="$nodeset">
    <xsl:sort select="rank"/>

    <xsl:if test="position() >= 1 and position() &lt; 11">
    <!-- Process the current node here -->
    </xsl:if>
    </xsl:for-each>

    or you could split it into two -- the xsl:sort as child of
    xsl:apply-templates and the check for the position() being in the
    correct range -- in the body of xsl:template.


    <xsl:apply-templates select="$nodeset">
    <xsl:sort select="rank"/>
    </xsl:apply-templates>

    and the matching template:

    <xsl:template match="somePattern">
    <xsl:if test="position() >= 1 and position() &lt; 11">
    <!-- Process the current node here -->
    </xsl:if>
    </xsl:template>

    If you need to be sure that this template will be instantiated only by
    the above xsl:apply-templates, then it is appropriate to set a mode on
    it and use it in the xsl:apply instruction.


    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL
    Dimitre Novatchev, Jul 23, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hajime Kusakabe

    DataGrid - sorting/paging problem

    Hajime Kusakabe, Jul 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    470
    Saravana
    Jul 31, 2003
  2. Replies:
    2
    Views:
    1,392
    James Kanze
    Jul 6, 2010
  3. Jason
    Replies:
    0
    Views:
    363
    Jason
    Oct 4, 2006
  4. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    458
    Michael Budash
    Oct 11, 2003
  5. Íéêüëáïò Êïýñáò

    Sorting a set works, sorting a dictionary fails ?

    Íéêüëáïò Êïýñáò, Jun 10, 2013, in forum: Python
    Replies:
    12
    Views:
    133
    Ulrich Eckhardt
    Jun 10, 2013
Loading...

Share This Page