xslt - How do I sort EventTime from xml document? -
i sort eventtime sample xml document have pasted. want display recent eventtime.
my sample xml document
<integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:ixml="http://tsgweb.com" xmlns:cmcodequeryhelper="urn:cmcodequeryhelper" packageid="ixml case notification test" messageid="67085056" xmlns=""> <case internalid="1617090499" id="12125626" xmlns:user="http://tylertechnologies.com"> <caseevent date="05/22/2015" id="160828152" internaleventid="1721879467" xmlns:reslib="urn:reslib"> <eventtime>8:49 am</eventtime> </caseevent> <caseevent date="05/28/2015" id="160828600" internaleventid="1721879818" xmlns:reslib="urn:reslib"> <eventtime>1:39 pm</eventtime> </caseevent> </case> </integration> xsl line of code sort not working
<xsl:sort select="substring-after-last(eventtime)" order="descending"/>
first, there no substring-after-last() function in xslt - not in xslt 3.0. , if there such function, need two arguments: string, , delimiter. , - importantly - don't see how such function of here.
the problem input eventtime values not in format xslt recognizes time. in order avoid interim steps of converting them first valid times , sortable number or string, use like:
<xsl:template match="case"> <xsl:copy> <xsl:apply-templates select="caseevent"> <!-- 1. before pm --> <xsl:sort select="substring-after(eventtime, ' ')" data-type="text" order="ascending"/> <!-- 2. 12th hour comes first --> <xsl:sort select="number(substring-before(eventtime, ':')='12')" data-type="number" order="descending"/> <!-- 3. sort hour --> <xsl:sort select="substring-before(eventtime, ':')" data-type="number" order="ascending"/> <!-- 4. sort minute --> <xsl:sort select="substring-before(substring-after(eventtime, ':'), ' ')" data-type="number" order="ascending"/> </xsl:apply-templates> </xsl:copy> </xsl:template>
Comments
Post a Comment