Skip to content

Instantly share code, notes, and snippets.

@jessgusclark
Created August 26, 2016 16:09
Show Gist options
  • Save jessgusclark/ebc35ad8dd76e52143c65e6d178116f8 to your computer and use it in GitHub Desktop.
Save jessgusclark/ebc35ad8dd76e52143c65e6d178116f8 to your computer and use it in GitHub Desktop.
Converting Dates from OU Campus to XS:Date
<?xml version="1.0" encoding="utf-8"?>
<?pcf-stylesheet path="date.xsl" title="Date Example" extension="htm"?>
<!DOCTYPE document SYSTEM "http://commons.omniupdate.com/dtd/standard.dtd">
<document xmlns:ouc="http://omniupdate.com/XSL/Variables">
<ouc:div label="content1" group="Everyone" button-class="oucEditButton" button-text="Col1 Content" break="break" button="hide"><ouc:editor csspath="/_resources/ou/editor/maincontent.css" cssmenu="/_resources/ou/editor/menu.txt" width="955" wysiwyg-class="maincontent"/></ouc:div>
<ouc:div label="artdate" group="Everyone" button-text="Edit Date"><ouc:multiedit type="date" format="iso" prompt="Date" alt="Date." maxlength="100"/>08/27/2016</ouc:div>
<div class="w3-border-bottom w3-border-top w3-border-gray">
<div class="section group" style="margin:0px; padding:0px;">
<div class="col span_1_of_2" style="padding-top: 6px;">
<p></p>
</div>
<div class="col span_1_of_2 fltright" style="padding-top: 6px;"><span class="fltright">{{a:2196}}</span>
</div>
</div>
</div>
</document>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ou="http://omniupdate.com/XSL/Variables"
xmlns:fn="http://omniupdate.com/XSL/Functions"
xmlns:ouc="http://omniupdate.com/XSL/Variables"
exclude-result-prefixes="ou xsl xs fn ouc">
<xsl:template name="temp" match="/document">
<html lang="en">
<head>
<link href="//netdna.bootstrapcdn.com/bootswatch/3.1.0/cerulean/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<h1>Dates!</h1>
<!-- get date as string from pcf in format mm/dd/yyyy -->
<xsl:variable name="stringDate" select="ouc:div[@label='artdate']" />
<!-- convert the date into an array so it can be rearranged for xs:date -->
<xsl:variable name="arrayDate" select="tokenize( $stringDate, '/')" />
<!-- convert arrayDate to xs:date in the format yyyy-mm-dd which is the XML standard -->
<xsl:variable name="date" as="xs:date" select="xs:date( concat( $arrayDate[3], '-', $arrayDate[1], '-', $arrayDate[2] ) )" />
<!-- convert the date -->
<strong>Original: </strong> <xsl:value-of select="$stringDate" /><br/>
<strong>Converted: </strong><xsl:value-of select="format-date( $date , '[MNn] [D01], [Y0001]')" /> <!-- August 26, 2016 -->
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment