[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1051
  • Last Modified:

Date manipulation in XSL

I need to transform a source XML file and add some date processing to the output. The output needs to be another XML file, not HTML for a browser. The date functions work fine but the output is not XML -  trying to translate the XML via .Net 1.1 VB code produces the following exception message: File:///c:/<path>/DateToday.xsl(9,2):

All I get is the following string when I open DateToday.XML in IE6
Fred22/05/2006 16:22:3122/07/2006 16:22:3161

My test files are as follows:

Input file DateToday.XML
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="DateToday.xsl"?>


Translation file DateToday.XSL
<?xml version="1.0" encoding="Windows-1252" ?>
<xsl:output method="xml" encoding="utf-8" />

<xsl:include href="DateLibrary.xsl"/>

<xsl:template match="/">

<xsl:variable name="DateToday" select="extra:FormatDateToday()"/>
<xsl:variable name="CalculatedDate" select="extra:AddDate('m',2,$DateToday)"/>
<xsl:variable name="DateDifference" select="extra:DiffDate('d',$DateToday,$CalculatedDate)"/>

    <xsl:value-of select="//DateNow"/>
    <xsl:value-of select="$DateToday"/>
    <xsl:value-of select="$CalculatedDate"/>
    <xsl:value-of select="$DateDifference"/>



Date processing function file DateLibrary.XSL
<msxsl:script xmlns:msxsl="urn:schemas-microsoft-com:xslt"
Function AddDate(Interval, NumberOfIntervals, Date)
  AddDate = FormatDateTime(DateAdd(Interval, NumberOfIntervals, Date))
End Function
Function FormatDateToday()
  FormatDateToday = FormatDateTime(Now(),0)
End Function

Function FormatDateAndTime(SelectedDate, FormatType)
  FormatDateAndTime = FormatDateTime(SelectedDate, FormatType)
End Function

Function DiffDate(Interval, Date1, Date2)
  DiffDate = DateDiff(Interval, Date1, Date2)
End Function


1 Solution
Geert BormansCommented:
Hi MBL1175,

your XSLT works fine
the problem is your browser.
The browser threats the XML result as if it were HTML
and for that the browser ignores the unknown tags... showing you only the text content, not the tags

if you download msxsl from the microsoft website
you can run the following on the commandline

msxsl DateToday.xml DateToday.xsl -o DateResult.xml

you will see that DateResult.xml contains your expected xml

MBL1175Author Commented:
Hi Gertone

Thanks for the update - MSXSL worked just fine.

However, I don't understand why I don't get the same result from the transformation in my VB code. Can you shed any light on why MSXSL works but VB.Net doesn't??


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now