Skip to main content

Office of Information Technology (OIT)

UT Arlington
OIT: Office of Information Technology

helpdesk@uta.edu ·  Work Order · 817-272-2208 · System Status

We are your IT partner!

XSLT

Date/Time AM/PM

The HannonHill delivered Xalan extension and Javascript function for date/time conversion has a bug. The Unix time is military style, the hour having a value from 0 - 23. This is the corrected Javascript, setting a.m. or p.m. depending on time of the day:

 

           function convertDate(date)
            {
                var months = new Array(13);
                months[0]  = "January";
                months[1]  = "February";
                months[2]  = "March";
                months[3]  = "April";
                months[4]  = "May";
                months[5]  = "June";
                months[6]  = "July";
                months[7]  = "August";
                months[8]  = "September";
                months[9]  = "October";
                months[10] = "November";
                months[11] = "December";
               
                var d = new Date(date); // Splits date into components
                var month = months[d.getMonth()];
                var date = d.getDate();
                var hours = d.getHours();
                var ampm = "a.m.";
               
                if (hours > 11) {
                    ampm = "p.m.";
                }

                if (hours > 12) {
                    hours = hours - 12;
                }
               
                if (hours == 0) {
                    hours = 12;
                }
               
                return hours + " " + ampm + " " + month + " " + date;
            }

 

The original version had the first 2 if statements in reverse order.  Which means the logic for a.m. and p.m. would never work, since the hours had already been converted to American time.

 

Category Grouping in Cascade Server

The best solution for grouping and sorting of system-pages is the Muenchian method:

http://www.hannonhill.com/news/blog/2008/Muenchian-Grouping-in-Cascade-Server.html

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="pages-by-category" match="system-page" use="dynamic-metadata[name = 'Category']/value" />
    <xsl:template match="/system-index-block">
            <xsl:for-each select=".//system-page[generate-id() = generate-id(key('pages-by-category', dynamic-metadata[name = 'Category']/value)[1])]">
                <xsl:sort select="dynamic-metadata[name = 'Category']/value" />
                <h1><xsl:value-of select="dynamic-metadata[name = 'Category']/value" /></h1>
                    <ul>
                        <xsl:for-each select="key('pages-by-category', dynamic-metadata[name = 'Category']/value)">
                            <xsl:sort select="display-name" />
                            <xsl:apply-templates select="." />
                        </xsl:for-each>
                    </ul>
            </xsl:for-each>
    </xsl:template>
  
    <xsl:template match="system-page">
        <li><xsl:value-of select="display-name"/></li>
    </xsl:template>
</xsl:stylesheet>