xsl-list
[Top] [All Lists]

Sorting results by output of a conversion template

2004-01-08 21:47:14
Hi,

I have some sophisticated sorting to do and only a basic level of
knowledge.

Essentially, I have an element coming down called 'assignStartTime' which
holds a three-digit numeric value e.g. 181, 145, 85, 133 etc etc. Now,
these figures actually represent a time and once passed through to a
conversion template (called 'convertApptEndTime'), return a figure like
12:00pm or 3:00pm etc etc. The conversion template looks like this:

<xsl:template name="convertApptStartTime">
      <xsl:param name="node"/>

      <xsl:variable name="hour" select="number(floor((($node - 1)*5) div
60))"/>

      <!-- get transformed start time value -->
      <xsl:call-template name="convertApptStartTimeShort">
         <xsl:with-param name="node" select="$node"/>
      </xsl:call-template>

      <xsl:choose>
            <xsl:when test="$hour &gt;= 12">
                  <xsl:text>pm</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                  <xsl:text>am</xsl:text>
            </xsl:otherwise>
      </xsl:choose>
</xsl:template>

<xsl:template name="convertApptStartTimeShort">
      <xsl:param name="node"/>

      <xsl:variable name="hour" select="number(floor((($node - 1)*5) div
60))"/>
      <xsl:variable name="minute" select="number((($node - 1)*5) mod 60)"/>

      <xsl:choose>
            <xsl:when test="$hour &gt; 12">
                  <xsl:if test="$minute &gt; 9">
                        <xsl:value-of select="number($hour -
12)"/>:<xsl:value-of select="$minute"/>
                  </xsl:if>
                  <xsl:if test="$minute &lt; 10">
                        <xsl:value-of select="number($hour -
12)"/>:0<xsl:value-of select="$minute"/>
                  </xsl:if>
            </xsl:when>
            <xsl:otherwise>
                  <xsl:if test="$minute &gt; 9">
                        <xsl:value-of select="$hour"/>:<xsl:value-of select
="$minute"/>
                  </xsl:if>
                  <xsl:if test="$minute &lt; 10">
                        <xsl:value-of select="$hour"/>:0<xsl:value-of
select="$minute"/>
                  </xsl:if>
            </xsl:otherwise>
      </xsl:choose>
</xsl:template>


I need to be able to sort my results by the output of this template.
So...is there a way using XSL:SORT to call a template (like the one above)
and sort the results that way?? e.g. I'm using xsl:for-each to run through
my XML elements and call a tableRow template which produces the HTML..
Somehow, I'd like to sort via time as noted in bold in the xsl:sort
statement below.


<xsl:for-each select="startTime">

      <xsl:sort select="OUTPUT-FROM-MY-CONVERSION-TEMPLATE"/>

      <xsl:call-template name="tableRow">
            <xsl:with-param name="pColour" select="'#EEEEFF'"/>
      </xsl:call-template>

</xsl:for-each>


I don't know if it's possible or not but many thanks for your time.

Regards
Allan







Important:  This e-mail is intended for the use of the addressee and may 
contain information that is confidential, commercially valuable or subject to 
legal or parliamentary privilege.  If you are not the intended recipient you 
are notified that any review, re-transmission, disclosure, use or dissemination 
of this communication is strictly prohibited by several Commonwealth Acts of 
Parliament.  If you have received this communication in error please notify the 
sender immediately and delete all copies of this transmission together with any 
attachments.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>