Re: RE: How do I concatenate date and time from xml document?
Posted: Thu Aug 25, 2022 8:32 am
Hi,
Here's a small example, I only took the start time into account, the end time can be taken into account similarly:
Regards,
Radu
Here's a small example, I only took the start time into account, the end time can be taken into account similarly:
Code: Select all
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Setting">
<xsl:variable name="tokenizedHD" select="tokenize(HearingDate/text(), '/')"/>
<xsl:variable name="dateInYYYYMDDFormat" select="concat($tokenizedHD[3], '/', $tokenizedHD[2], '/', $tokenizedHD[1])"/>
<xsl:variable name="startTimeIn24HFormat">
<xsl:choose>
<xsl:when test="contains(CourtSessionBlock/StartTime, 'AM')">
<xsl:value-of select="tokenize(CourtSessionBlock/StartTime, ' ')[1]"/>
</xsl:when>
<xsl:otherwise>
<!-- PM hour, convert to 24 hour format -->
<xsl:variable name="time" select="tokenize(CourtSessionBlock/StartTime, ' ')[1]"/>
<xsl:variable name="hours" select="xs:int(tokenize($time, ':')[1])" as="xs:int"/>
<xsl:variable name="minutes" select="xs:int(tokenize($time, ':')[2])" as="xs:int"/>
<xsl:value-of select="concat($hours + 12, ':', $minutes)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="finalDate" select="concat($dateInYYYYMDDFormat, 'T', $startTimeIn24HFormat)"/>
<xsl:value-of select="$finalDate"/>
</xsl:template>
</xsl:stylesheet>
Radu