- Details
- Written by Ross
Formatting a date in XSLT is a pain, so the more examples their are online the better i think.
I was required to convert a date in a US format mm/dd/yy hh:min AM/PM to the xml standard YYYY-MM-DDTHH24:MIN:SS
I started of using the tamplate found at the bottom of http://stackoverflow.com/questions/16484193/convert-date-from-dd-mmm-yyyy-to-yyyymmdd-format-in-xslt-1-0 and altered it match my needs.
The original template did not handle checking for AM/PM and the year represented as yy.
<xsl:template name="date">
<xsl:param name="slashFormattedDate"/>
<xsl:param name="hasTime"/>
<xsl:variable name="dd"
select="format-number(substring-before($slashFormattedDate, '/'),'00')"/>
<xsl:variable name="monthYear"
select="substring-after($slashFormattedDate, '/')"/>
<xsl:variable name="mm" select="format-number(substring-before($monthYear, '/'),'00')"/>
<xsl:variable name="yyyyTemp1" select="substring-after($monthYear, '/')"/>
<xsl:variable name="yyyyTemp2">
<xsl:choose>
<xsl:when test="$hasTime='Y'">
<xsl:value-of select="substring-before($yyyyTemp1, ' ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$yyyyTemp1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="yyyy">
<xsl:choose>
<xsl:when test="string-length($yyyyTemp2) = 2 and $yyyyTemp2 > 50">
<xsl:value-of select="concat('19',$yyyyTemp2)"/>
</xsl:when>
<xsl:when test="string-length($yyyyTemp2) = 2 and $yyyyTemp2 <= 50">
<xsl:value-of select="concat('20',$yyyyTemp2)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$yyyyTemp2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="timeTemp">
<xsl:choose>
<xsl:when test="$hasTime='Y'">
<xsl:value-of select="substring-after($yyyyTemp1, ' ')"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="time">
<xsl:choose>
<xsl:when test="substring-after($timeTemp, ' ') = 'PM' and number(substring-before($timeTemp, ':')) < 12">
<xsl:value-of select="concat(number(substring-before($timeTemp, ':'))+12,':',substring-after(substring-before($timeTemp,' '), ':'),':00')"/>
</xsl:when>
<xsl:when test="contains($timeTemp,' ')">
<xsl:value-of select="concat(format-number(substring-before($timeTemp, ':'),'00'),':',substring-after(substring-before($timeTemp,' '), ':'),':00')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(format-number(substring-before($timeTemp, ':'),'00'),':',substring-after($timeTemp,':'),':00')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$hasTime='Y'"><xsl:value-of select="$yyyy" disable-output-escaping="yes"/>-<xsl:value-of select="$mm" disable-output-escaping="yes"/>-<xsl:value-of select="$dd" disable-output-escaping="yes"/>T<xsl:value-of select="$time" disable-output-escaping="yes"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$yyyy" disable-output-escaping="yes"/>-<xsl:value-of select="$mm" disable-output-escaping="yes"/>-<xsl:value-of select="$dd" disable-output-escaping="yes"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
- Details
- Written by Ross
Firstly I installed joomla setup files in a new directory /var/www/techknowledgebase
, there are plenty of guides telling you how, these are some off the websites i used
http://forum.joomla.org/viewtopic.php?t=287999
https://docs.joomla.org/J3.x:Installing_Joomla
https://www.joomla.org/download.html
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
I already had joomla installed for another site, so i knew apache2 php and mysql where already set up.
The only additional thing that i have done up to now is
added
Listen 8080
to /etc/apache2/ports.conf
and added
<VirtualHost *:8080>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/techknowledgebase
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory /var/www/techknowledgebase>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
into /etc/apache2/sites-available/000-default.conf
Below the existing virtualHost configuration.
Restart apache2 service apache2 restart
This is essentially a copy of the original configuration but i have changed the port to 8080 and changed Directory
and DocumentRoot
values to point to the path of my new site on the server. i put it below the existing configuration as i want to go to my first site by default if the IP address is used.
My next step is to configure my domain to point to my server, update the VirtualHost configuation to use my domain name and not the 8080 port, and remove the 8080 port from listening address
While i wait for DNS configuration changes to take affect i used my server ip and port 8080 to follow joomla installation instructions.
----
Once i had a DNS set up and pointing to my server i needed to tell apache2 to recognise it was comming from this site, not my other site.
i changed /etc/apache2/sites-available/000-default.conf
to include the ServerName
and ServerAlias
values. and reset the port to 80
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.techknowledgebase.co.uk
ServerAlias techknowledgebase.co.uk *.techknowledgebase.co.uk
ServerAdmin webmaster@localhost
DocumentRoot /var/www/techknowledgebase
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory /var/www/techknowledgebase>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
i removed Listen 8080
from /etc/apache2/ports.conf
I also needed to add ServerName
and ServerAlias
for my existing site so that it would go to the correct site
Finally Restart apache2 service apache2 restart
Subcategories
Computing Article Count: 1
Any Computing Related Blog Entries