Results 1 to 2 of 2

Thread: xsl:sort .::RESOLVED::.

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    52

    xsl:sort .::RESOLVED::.

    Hi.

    I'm trying to sort a node by an attribute of it's last child.
    The way I understand things, the following code SHOULD work, but it only sorts the nodes in the reverse order they were entered, and not by the date & time.

    xsl template extract
    Code:
    <xsl:template match="topic" mode="toc">
    	<xsl:apply-templates select="subject" mode="toc">
    		<xsl:sort select="message[last()]/@dd" data-type="number" order="descending"/>
    		<xsl:sort select="message[last()]/@mm" data-type="number" order="descending"/>
    		<xsl:sort select="message[last()]/@yyyy" data-type="number" order="descending"/>
    		<xsl:sort select="message[last()]/@time" data-type="number" order="descending"/>
    	</xsl:apply-templates>
    </xsl:template>

    xml file extract
    Code:
    <forum>
      <category name="Category 1 New new" dd="13" mm="11" yyyy="2002" time="15:57:42" type="c" id="1">
        <topic name="New" description="Testing 55" username="ashleym" alias="Ashes" dd="13" mm="11" yyyy="2002" time="15:50:06" type="t" id="1">
          <subject name="blah" username="ashleym" alias="Ashes" read="52" dd="13" mm="11" yyyy="2002" time="15:12:47" type="s" id="1">
            <message username="ashleym" alias="Ashes" dd="13" mm="11" yyyy="2002" time="15:12:47" type="m" id="1">[}:)]</message>
            <message username="ashleym" alias="Ashes" dd="13" mm="11" yyyy="2002" time="15:12:58" type="m" id="2">hu????</message>
            <message username="ashleym" alias="Ashes" dd="13" mm="11" yyyy="2002" time="15:13:03" type="m" id="3">what?</message>
            <message username="ashleym" alias="Ashes" dd="13" mm="11" yyyy="2002" time="15:13:33" type="m" id="4">not you again</message>
            <message username="ashleym" alias="Ashes" dd="13" mm="11" yyyy="2002" time="15:51:06" type="m" id="5">Oh yes[;)]</message>
            <message username="ashleym" alias="Ashes" dd="14" mm="11" yyyy="2002" time="09:19:24" type="m" id="7">blah</message>
            <message username="ashleym" alias="Ashes" dd="14" mm="11" yyyy="2002" time="10:37:39" type="m" id="10">hey?</message>
          </subject>
        </topic>
      </category>
    </forum>

    Sorry I don't really know how to explain this any better.
    Any help will be appreciated.
    Thanks
    Last edited by Ashes; Nov 14th, 2002 at 05:22 AM.

  2. #2

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    52
    Don't worry, figured it out (seem to be doing a lot of that lately

    Just had to split up the time (take out the ":"s)

    Code:
    		<xsl:sort select="substring(@time,1,2)" data-type="number" order="{$sortOrder}"/><!--Hour-->
    		<xsl:sort select="substring(@time,4,2)" data-type="number" order="{$sortOrder}"/><!--Minute-->
    		<xsl:sort select="substring(@time,7,2)" data-type="number" order="{$sortOrder}"/><!--Second-->
    Can't believe I was so dumb really.
    Later.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width