Ik gebruik het volgende xsl zowel in Xalan als MSXML3. Het vervelende is nu dat ik op deze manier het javascript 2 keer in het stylesheet moet zetten.
Weet iemand een manier om dit te voorkomen?
Weet iemand een manier om dit te voorkomen?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
| <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lxslt="http://xml.apache.org/xslt"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:js="http://www.interspective.nl/js">
<lxslt:component prefix="js" functions="getDays">
<lxslt:script lang="javascript">
function getDays(month, date)
{
if (month == "" || date == "")
return 40000000000;
month = parseInt(month, 10);
date = parseInt(date, 10);
now = new Date();
nowYear = now.getFullYear();
nowMonth = now.getMonth() + 1;
nowDate = now.getDate();
year = nowYear;
if (month < nowMonth ||
(month == nowMonth && date < nowDate))
year++;
then = new Date(year, month - 1, date);
divMillis = then.getTime() - now.getTime();
return divMillis;
}
</lxslt:script>
</lxslt:component>
<msxsl:script language="JScript" implements-prefix="js">
function getDays(month, date)
{
if (month == "" || date == "")
return 40000000000;
month = parseInt(month, 10);
date = parseInt(date, 10);
now = new Date();
nowYear = now.getFullYear();
nowMonth = now.getMonth() + 1;
nowDate = now.getDate();
year = nowYear;
if (month < nowMonth ||
(month == nowMonth && date < nowDate))
year++;
then = new Date(year, month - 1, date);
divMillis = then.getTime() - now.getTime();
return divMillis;
}
</msxsl:script>
<xsl:template match="/">
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name(.)}">
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="*" mode="child">
<xsl:sort
select="js:getDays(string(birthDate/month), string(birthDate/day))"
data-type="number"
order="ascending"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="*" mode="child">
<xsl:element name="{name(.)}">
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:copy-of select="*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet> |