RE: How do I concatenate date and time from xml document?
Questions about XML that are not covered by the other forums should go here.
Re: RE: How do I concatenate date and time from xml document?
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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service