Do I need JavaScript to transform dates to DayOfYear in Visual Studio 2008 and XML Spy?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-size:12.0pt Hi, Iâm looking for the best way to transform a date/time into a DayOfYear, from the following simplified document:
<p style="margin-bottom:.0001pt; line-height:normal; text-autospace:none <span style="color:#0000ff; font-family:Consolas; font-size:small
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; myNode<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; myDate<span style="color:Blue; >2011-04-26T13:26:19-05:00<span style="color:Blue; </<span style="color:#A31515; myDate<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; myNode<span style="color:Blue; >
[/code]


<p style=" <span style="font-size:12.0pt; line-height:115% I would like this to work in both Visual Studio 2008 and in XML Spy 2011.
<span style="font-size:12.0pt; line-height:115% I came up with a way to detect with JavaScript which environment itâs running in:
<p style="margin-bottom:.0001pt; line-height:normal; text-autospace:none <span style="color:#0000ff; font-family:Consolas
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; xmlns:xsl<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/1999/XSL/Transform<span style="color:Black; "
<span style="color:Red; xmlns:ms<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; urn:schemas-microsoft-com:xslt<span style="color:Black; " <span style="color:Red; xmlns:fmt<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; fmt<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ms<span style="color:Blue; :<span style="color:#A31515; script <span style="color:Red; language<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; javascript<span style="color:Black; " <span style="color:Red; implements-prefix<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; fmt<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <![CDATA[<span style="color:Gray;
function DayOfYear(node) { // support Visual Studio
var val;
if (Object.prototype.toString.call(node) == [object XPathArrayIterator]) {
node.MoveNext();
val = node.Current.Value;
}
else { // support XML Spy
val = node;
}
var yr = val.substring(0,4);
var mo = val.substring(5,7);
var dy = val.substring(8,10);
var dt = new Date(yr, mo-1, dy);
return dayOfYear(dt);
}

function dayOfYear(dt) {
var jan1 = new Date(dt.getFullYear(), 0, 1);
const msecPerDay = 86400000;
return Math.ceil((dt - jan1) / msecPerDay) + 1;
}
<span style="color:Blue; ]]>
<span style="color:Blue; </<span style="color:#A31515; ms<span style="color:Blue; :<span style="color:#A31515; script<span style="color:Blue; >
...
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; fmt:JTime(myNode/myDate)<span style="color:Black; " <span style="color:Blue; />
[/code]


<p style="margin-bottom:.0001pt; line-height:normal; text-autospace:none <span style="font-size:16px; line-height:18px If Visual Studio 2008 supported XSLT v2.0, I could do this in simple XSLT without any JavaScript:
<span style="font-size:12.0pt; line-height:115%
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; formatDateWithXsltV2<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; param <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; dt<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; a<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; <span style="color:Blue; format-dateTime($dt, "[d]")<span style="color:Black; <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $a<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template<span style="color:Blue; >
[/code]

<hr class="sig C#/ASP.NET/SQL/VB developer

View the full article
 
Back
Top