HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Windows/System32/zh-TW/energy.dll.mui
MZ����@���	�!�L�!This program cannot be run in DOS mode.

$5�<�q�R�q�R�q�R�e���p�R�e�P�p�R�Richq�R�PEL�!�

��@ ��8.rdata�@@.rsrc� �@@�xȖ
T88�xȖ$��8.rdata8x.rdata$zzzdbg 0	.rsrc$010)�#.rsrc$02 Հ8Ee.x~\��MB�i<���M�w��xȖ8�8�P�p�������"9��?�@�E0�FH�L`�Mx�N��O��P��Q��R��S�X �Y8�^P�_h�e��f��k��l��m��n��o�p(�q@�rX�sp�w��x��~����������0�@�H�t�`���x�����������(8HXhx��������(8HXhx��������(0)���)���*l�+d��+��,��`.���/�2J�P4��L68��8���:��;B��<��=|�x?��@$�,B���B���C$��E,��H��tKh��MD� R��V�Z�\0�D]Z��]T��]���_��d`.��`(��` ��`t�Pd���LI�F������T�MUIIDR_XML_BATTERY_TRANSFORMIDR_XML_DEFAULT_TRANSFORM.XSL"IDR_XML_SLEEPDIAGNOSTICS_TRANSFORMIDR_XML_SLEEPSTUDY_TRANSFORM�����X$��.���f��w���n�t�%�o����MUIzh-TWR�g1YWeR�g1YWe0��S��/f�V�p��d��jHh
d�kb�N�N��N�h0R�g/����RR�g1YWe0�RP}�g�S(u�FO�S��
N�[te0R�gb�RR�gb�R0*g|v�s�NUO���nHe�sOUL�0�l	g�P�V�NUOnj
�0PA�|q}nj
��|q}nj
��|q}nj
�s�0}nj�e��f�
T1z�|q}�� �FU�|q}"u�T
T1zBIOS �egBIOS Hr,g\Omi�|q}D}�^�}_�s^�S҉r�U�tz�^�xe�WL��}�xeN,����ns^�S�BfhV㉐g�^s^�S�BfhV㉐g�^c�-��vs^�S�BfhV㉐g�^/f 15.6ms (15625000ns)�N�a(W�k!k�|q}��nBfO(u0�Y�g�BfhV㉐g�^�X�R�GRU�thV���n�{t�bS�1\g�l	gHe�s0�BfhV㉐g�^�S��g�V�p�d>eY�ZԚbWb_�Rku��X�R0PA�vMR�v�BfhV㉐g�^ (100ns P�UMO)g'Y�BfhVg�� (100ns P�UMO)	*g�WL��v�BfhV��Blz_b
g�R��Bl�v�BfhV㉐g�^\�es^�Sg'Y�BfhV㉐g�^0��Bl�vg��ck(W��BlU�tz�^X�%R�x
ck(W��BlU�tz�^_*g�WL��v8h�_�BfhV��Bl!8h�_CQ�Nb݈nE��Rz_��Bl�v�BfhV㉐g�^\�es^�Sg'Y�BfhV㉐g�^0��Bl�vg����Bl�xez_b
g�R��Bl�v�BfhV㉐g�^'Y�ebI{�es^�Sg'Y�BfhV㉐g�^0�BfhV��BlX�udkU�tz�^-N����gNOs^�S�BfhV-��[�v!jD}X�u0|T�S!jD}PA���n�SGRO(u-N���n��R�vMRck(WO(u�v���n��R��R GUID
���n��Ryr� (O(u��`l)�vMR�v���n��R(W�|q}O(u��`l���RBf�vyr�0yr����n��Ryr�/fؚHe�� (O(u��`l)�vMR�v���n��R(W�|q}O(u��`l���RBf�vyr�/fؚHe��0\P(uo�:yhV>�Bf (O(u��`l)o�:yhV*g-��[�p(WN�kBf��
N;m�RKN�_ܕ��0
w�o�:yhV>�Bf (O(u��`l)o�:yhV-��[�p 5 R�KN�_ܕ��0>�Bf (�y)
\P(u���f>�Bf (O(u��`l)PAo�:yhV*g-��[�p(WN�kBf��
N;m�RKN�_��R���f0w����f>�Bf (O(u��`l)o�:yhV-��[�p 5 R�KN�_��R���f0>�Bf (�y)
\P(u�x�x��n (O(u��`l)�x�x*g-��[�p(WN�kBf��
N;m�RKN�_ܕ��0w��x�x>�Bf (O(u��`l)�x�x-��[�p 30 R�KN�_ܕ��0>�Bf (�y)
\P(uaw w>�Bf (O(u��`l)��f�*g-��[�p(WN�kBf��
N;m�RKN�_��R2�eQaw w�rKa0w�aw w>�Bf (O(u��`l)��f�-��[�p 30 R�KN�_��R2�eQaw w�rKa0>�Bf (�y)gNOU�thVHe���rKa/f 100% (O(u��`l)U�thV*g-��[�p9h�d;m�R��RM�NO���ϑ0PAؚgNOU�thVHe���rKa (O(u��`l)gNOU�thVHe���rKa��N�gؚU�thVHe���v 75%0gNOHe���rKa (TOgؚHe���v~vR�k)\P(uU�thV��n�rKa (O(u��`l)�vMR�vU�thV���n�{t�SGR�]\P(uNO���nU�thV��n�rKa0\P(u USB x��d'`�f\P (O(u��`l)�vMR�v���n�SGR�]hQ�W\P(u USB x��d'`�f\P�R��0802.11 !q�}���l���n�SGR/fgؚHe�� (O(u��`l)$�vMR 802.11 �v�[!q�}�}��Nb�aS�v���n�SGR*g-��[�pO(uNO���n!j_0PCI Express ASPM �]\P(u (O(u��`l)*�vMR PCI Express \O(u�rKa���n�{t (ASPM) �v���n�SGR-��[�pܕ��0PA
���n��Ryr� (N,����n)�vMR�v���n��R(W�|q}O(uN,����nBf�vyr�0���n��Ryr�/fؚHe�� (N,����n)�vMR�v���n��R(W�|q}O(uN,����nBf�vyr�/fؚHe��0\P(uo�:yhV>�Bf (N,����n)o�:yhV*g-��[�p(WN�kBf��
N;m�RKN�_ܕ��0
w�o�:yhV>�Bf (N,����n)o�:yhV-��[�p 10 R�KN�_ܕ��0
\P(u���f>�Bf (N,����n)o�:yhV*g-��[�p(WN�kBf��
N;m�RKN�_��R���f0w����f>�Bf (N,����n)o�:yhV-��[�p 10 R�KN�_��R���f0
\P(u�x�x��n (N,����n)�x�x*g-��[�p(WN�kBf��
N;m�RKN�_ܕ��0w��x�x>�Bf (N,����n)�x�x-��[�p 30 R�KN�_ܕ��0
\P(uaw w>�Bf (N,����n)��f�*g-��[�p(WN�kBf��
N;m�RKN�_��R2�eQaw w�rKa0w�aw w>�Bf (N,����n)��f�-��[�p 30 R�KN�_��R2�eQaw w�rKa0gNOU�thVHe���rKa/f 100% (N,����n)U�thV*g-��[�p9h�d;m�R��RM�NO���ϑ0ؚgNOU�thVHe���rKa (N,����n)gNOU�thVHe���rKa��N�gؚU�thVHe���v 75%0\P(uU�thV��n�rKa (N,����n)�vMR�vU�thV���n�{t�SGR�]\P(uNO���nU�thV��n�rKa0\P(u USB x��d'`�f\P (N,����n)�vMR�v���n�SGR�]hQ�W\P(u USB x��d'`�f\P�R��0802.11 !q�}���l���n�SGR/fgؚHe�� (N,����n)$�vMR 802.11 �v�[!q�}�}��Nb�aS�v���n�SGR*g-��[�pO(uNO���n!j_0PCI Express ASPM �]\P(u (N,����n)*�vMR PCI Express \O(u�rKa���n�{t (ASPM) �v���n�SGR-��[�pܕ��0��
��T� (O(u��`l)(�� Windows Media Player (W�d>e��
�BfgsOS�T�b�{w���R0�T�!j_��
��T� (N,����n)(�� Windows Media Player (W�d>e��
�BfgsOS�T�b�{w���R0�|q}�S(u'`��Bl�|q}�Bl��Blz_�]|v�Q��Bl�2�bk�|q}��R2�eQaw w�rKa0ck(W��BlU�tz�^�|q}�Bl��Bl
g�R�]|v�Q��Bl�2�bk�|q}��R2�eQaw w�rKa0ck(W��Bl
g�R�|q}�Bl��Bl݈nbE��Rz_�]|v�Q��Bl�2�bk�|q}��R2�eQaw w�rKa0
ck(W��BlE��Rz_�O�
ck(W��BlE��Rz_݈nPA�|q}�Bl��Bl8h�_CQ�N�]|v�Q��Bl�2�bk�|q}��R2�eQaw w�rKa0o�:yhV�Bl��Blz_�]|v�Q��Bl�2�bko�:yhV��R2�eQNO���n!j_0▋�!j_��Blz_�]|v�Q_U(u▋�!j_�v��Bl0▋�!j_��Bl
g�R�]|v�Q_U(u▋�!j_�v��Bl00����WL�
0��Blz_�]|v�Q0����WL�
0��Bl00����WL�
0��Bl
g�R�]|v�Q0����WL�
0��Bl0PAUSB �f\PUSB ݈n*g2�eQx��d'`�f\P�rKaLdk݈n*g2�eQ USB x��d'`�f\P�rKa0vudk USB ݈n
N/fU��ex��d'`�f\P�rKaBf��S��gq_��U�thV���n�{t0ˊ�la�dkOUL�
Ng �b�|q}!q�l2�eQaw w�rKa0;N_j�c6RhVX�%R�x;N_j�c6RhVMOn݈nX�%R�x#��c�W_PAUSB ݈n�_\2�eQx��d'`�f\P�rKaTdk݈n(W��d�g���e�e�~�~2�eQ USB x��d'`�f\P�rKa0vudk USB ݈n
N/fU��ex��d'`�f\P�rKaBf��S��gq_��U�thV���n�{t0ˊ�la�dkOUL�
Ng �b�|q}!q�l2�eQaw w�rKa0	�f\P�vBf�� (%)�S�VdkͅYr USB ݈n
N/e�cx��d'`�f\P��V�pr�݈n!q�l�L��O��0dkͅYr USB ݈n
N/e�cx��d'`�f\P��V�pr�݈n!q�l`��z�U��0CPU O(u�sNOU�thVO(u�s*��d�g���vs^GWU�thVO(u�s�_NO0vus^GW�vU�thVO(u�s^�8^NOBf��|q}g�(u�\ϑ���n0	s^GWO(u�s (%)-N�^U�thVO(u�sO��d�g���vs^GWU�thVO(u�s-NI{0vus^GW�vU�thVO(u�s^�8^NOBf��|q}g�(u�\ϑ���n0�j��P%RU�tz�^�vU�thVO(u�s�$R�eTO=~U�thVO(u�sgؚ�v�a(uz_�
g�R0ؚU�thVO(u�sO��d�g���vs^GWU�thVO(u�s�_ؚ0vus^GW�vU�thVO(u�s^�8^NOBf��|q}g�(u�\ϑ���n0�j��P%RU�tz�^�vU�thVO(u�s�$R�eTO=~U�thVO(u�sgؚ�v�a(uz_�
g�R0wQ	gؚU�thVO(u�s�vP%RU�tz�^0�PU�tz�^TO��d�g��@b��KN=~U�thVO(u�s�vN'Y�R0U�tz�^
T1zPID	s^GWO(u�s (%)!jD}s^GW!jD}O(u�s (%)��`l��`lnj
���`lX�%R�x�� �FU�� ��eg�^_�Sx[w�He�_�t�xe-���[ϑ
N!kEQ�n
N!kEQ�n (%)
N!k��`lEQ�nBf���`l2QX[�v���RNO�e-���[ϑ�v 50%0
N!kEQ�n (%)PA
N!kEQ�n (%)
N!k��`lEQ�nBf���`l2QX[�v���RNO�e-���[ϑ�v 40%0��`l�[ϑ
Nf!q�l$R�[��`l�[ϑ0��S��h�:y|vu̗Ԛ (BIOS) OUL�0�]�[\PAs^�S���n�{t�[ϑ/e�c�vaw w�rKapaw w�rKaAQ1���f�(WN�kBf��
N;m�RKN�_2�eQNO���n!j_0S3 aw w�rKa/f Windows s^�S�v�-�aw w�rKa0S3 aw w�rKa�Sg�m����N�OYu��aԚgQ�[�v���n�&NAQ1���f��_�b`�_K�\O0�S	gui\xes^�S/e�c S1 b S2 aw w�rKa0
/e�c S1 aw w�rKa
/e�c S2 aw w�rKa
/e�c S3 aw w�rKa
/e�c S4 aw w�rKa�]\P(u S1 aw w�rKa��V�p���f�-NwQ	g�]�w�v
N�v�[lxԚ0=Windows gݑ
\lxԚ�aw w�R��
N�v�[�v�R��f����R\P(uaw w�R��0�[݈g�eHr�v̗Ԛ (BIOS) sS�S�zl�POUL�0�]\P(u S2 aw w�rKa��V�p���f�-NwQ	g�]�w�v
N�v�[lxԚ0=Windows gݑ
\lxԚ�aw w�R��
N�v�[�v�R��f����R\P(uaw w�R��0�[݈g�eHr�v̗Ԛ (BIOS) sS�S�zl�POUL�0�]\P(u S3 aw w�rKa��V�p���f�-NwQ	g�]�w�v
N�v�[lxԚ0=Windows gݑ
\lxԚ�aw w�R��
N�v�[�v�R��f����R\P(uaw w�R��0�[݈g�eHr�v̗Ԛ (BIOS) sS�S�zl�POUL�0�|q}̗Ԛ (BIOS) 
N/e�c S30���f�
N�vlxԚ
N/e�c S3 aw w�rKa0�|q}̗Ԛ (BIOS) 
N/e�c S4 (O w)0���f�
N�vlxԚ
N/e�c S4 (O w) �rKa0�]\P(u S3 aw w�rKa��V�p���f�-NwQ	g�]�w�v
N�v�[lxԚ0=Windows gݑ
\lxԚ�aw w�R��
N�v�[�v�R��f����R\P(uaw w�R��0�[݈g�eHr�v̗Ԛ (BIOS) sS�S�zl�POUL�0
���n�SGR-N�]\P(uaw w�R��0�|q}�{t�T�]\P(udk�|q}
N�vaw w�R��0�]\P(uO w�R����V�p�|q}wQ	g*YY�[Ԛ��aԚ0�]\P(uO w�R����V�p2QX[P[�|q}|vu
NfOUL�0�]\P(uO w�R����V�p!q�l"uubX[�SO w�jHh0�]\P(uaw w��V�p�]�[݈
�Hr�vE��Rz_05aw w�R�����@b	g݈nE��Rz_GW����csS(u�N�S���n�{t�v�[0�Y�g�[݈�N
�Hr�vE��Rz_�1\g��R\P(uaw w�R��0E��Rz_
T1z�|q}CQ�N�]�fBf\P(u S1 aw w�rKa0�[݈NRCQ�Nbck(W2�L��]\OBf���f��S��!q�lI��c�aw w�rKa0&Microsoft �W,go�:yE��Rz_b Microsoft �W,gI�o�E��Rz_
Hypervisor�|q}�]�_[��dlx�x�jHh (VHD) ��_j0�|q}CQ�N�]�fBf\P(u S2 aw w�rKa0�[݈NRCQ�Nbck(W2�L��]\OBf���f��S��!q�lI��c�aw w�rKa0�|q}CQ�N�]�fBf\P(u S3 aw w�rKa0�[݈NRCQ�Nbck(W2�L��]\OBf���f��S��!q�lI��c�aw w�rKa0�|q}CQ�N�]�fBf\P(u SS4 (O w) �rKa0�[݈NRCQ�Nbck(W2�L��]\OBf���f��S��!q�lI��c�aw w�rKa0
/e�cH_'`o�:yhV�N�^0���f��S�� Windows ��R�c6RteT_o�:yhV�v�N�^0	H_'`o�:yhV�N�^/e�c9���f�
NAQ1� Windows ��R�c6RteT_o�:yhV�v�N�^0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0	U�thV���n�{t�R��	gHe�s�vU�thV���n�{t�S����f���Rs^a�He������n�m�0�D}"}_��n (C) �rKa�xeHe�� (P) �rKa�xe�{Am�� (T) �rKa�xe!q�lW�I� ACPI C2 �rKa/���f�
N�v C2 ��n�rKa�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI C3 �rKa/���f�
N�v C3 ��n�rKa�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI �{Am���rKa,���f�
N�v�{Am���rKa�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI _CST ir�N4���f�
N�v ACPI _CST ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI _CSD ir�N4���f�
N�v ACPI _CSD ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI _PCT ir�N4���f�
N�v ACPI _PCT ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI _PSS ir�N4���f�
N�v ACPI _PSS ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI XPSS ir�N4���f�
N�v ACPI XPSS ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI _PPC ir�N4���f�
N�v ACPI _PPC ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI _PSD ir�N4���f�
N�v ACPI _PSD ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI _PTC ir�N4���f�
N�v ACPI _PTC ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI _TSS ir�N4���f�
N�v ACPI _TSS ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI _TPC ir�N4���f�
N�v ACPI _TPC ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0!q�lW�I� ACPI _TSD ir�N4���f�
N�v ACPI _TSD ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0U�thV��n�rKa�}�Wb�T�xe
Nck�x0�[��pU�thV��n�}�Wb�T�vU�thVxe�v	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) �S�zl�POUL�0�}�WX�%R�x�g�vb�T�xe�[���vb�T�xeU�thVHe��b�{Am���rKa�}�Wb�T�xe
Nck�x6�[��pU�thVHe��b�{Am���rKa�}�Wb�T�vU�thVxe�v	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) �S�zl�POUL�0	\P(uU�thV��n�rKa:�]��R\P(uU�thV��n�rKa��V�p���f�-NwQ	g�]�w�v
N�v�[lxԚ0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0	\P(uU�thVHe���rKa:�]��R\P(uU�thVHe���rKa��V�p���f�-NwQ	g�]�w�v
N�v�[lxԚ0�[݈g�eHr�v�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0
\P(uU�thV�{Am���rKa9�]��R\P(uU�thV�{Am���rKa��V�p���f�-N	g�]�w�v
N�v�[lxԚ0�[݈g�eHr�|q}̗Ԛ (BIOS) sS�S�zl�POUL�0PCI Express \O(u�rKa���n�{t (ASPM) �]\P(u2�]\P(u PCI Express \O(u�rKa���n�{t (ASPM)��V�p���f�-NwQ	g�]�w�v
N�v�[lxԚ0!q�}X[�Sޞ
N/e�c WMM w��8��f�@b#��c�v!q�}X[�Sޞ
N/e�c WMM w��!j_0!q�}�}��Nb�aS!q�l2�eQ!q�}�Nb�aS���n�SGR@b�[��vw��!j_�Ow��0SSIDMAC MO@W#��}�_}T/e�c;0#��}�_}T
0AQ1���f�2�eQNO���n!j_����f�U��edk!j_BfN�_g��_U&N#��}0/e�cBf�gO(u0#��}�_}T
0��^��|q}aw w�rKa0/e�c#��}�_}T!q�lW�I�  ACPI PCCP ir�N5���f�
N�v ACPI PCCP ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) b1��S�zl�POUL�0!q�lW�I� ACPI _CPC ir�N5���f�
N�v ACPI _CPC ir�N�[�	gOUL�0�[݈g�eHr�v�|q}̗Ԛ (BIOS) b1��S�zl�POUL�0��n�rKa�xe��n�rKa^��W
M��[;��s (MHz)g'YHe��~vR�kg\He��~vR�kg\�{Am~vR�kHe���c6R^��W!qACPI He�� (P) / �{Am�� (T) �rKas^�S�Bf�c6RACPI qQT\OmiU�thVHe���c6RPA���n_�dY�cz_ACPI ��n (C) �rKa
Windows To Go0#��}�_}T
0�]�V�plxԚ
N�v�[�\P(u0,dk��f�/e�c0#��}�_}T
0�FONbYPlxԚCQ�N�dk�rKa�v�Bl
N&{0NRCQ�N!q�l�n����N�Bl:2QX[lxԚ!q�}�}��Nb�aSL��R�[;�lxԚ�
�lxԚ&{Tj�n
N&{Tj�n	�_���n_�dY�cz_݈nE��Rz_E��Rz_z�1Yb-��[/����v݈ng�X�R���R�v�m�0PA݈n
T1z݈nX�%R�x݈n�rKa݈nOUL��N�x!q�l��X��v݈naw wxvz�la: dk1XJT
NS+T,{NP0#��}�_}T
0�]\O���k�vnj
�0�,{NP0#��}�_}T
0�]\O���k�Y�e��e�vBf���{
W0�Y�g
\��e�vBf���{
Wa����ˊO(u &lt;code&gt;powercfg sleepstudy -duration DURATION&lt;/code&gt;0�O�Y�傁�R�gN��S 10 )Y�ˊO(u:&lt;br /&gt;&lt;pre&gt;powercfg sleepstudy -duration 10&lt;/pre&gt;
|v�s_U�R��vR�g/���
|v�s Fx ݈n�vR�g/���|v�s PDC ���k�vR�g/���PDC ���kg���v=~�T'Y�e CS g��0PA�|q}�N�N���jPA݈n
T1zPPnj
�

t4VS_VERSION_INFO��
aJ
aJ?�StringFileInfo�040404B0LCompanyNameMicrosoft Corporation6FileDescription���nHe�s:��eh$FileVersion10.0.19041.1 (WinBuild.160101.0800)6InternalNameenergy.dll�.LegalCopyright� Microsoft Corporation. All rights reserved.FOriginalFilenameenergy.dll.muij%ProductNameMicrosoft� Windows� Operating System>
ProductVersion10.0.19041.1DVarFileInfo$Translation�<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ms="urn:schemas-microsoft-com:xslt"
    xmlns:bat="http://schemas.microsoft.com/battery/2012"
    xmlns:js="http://microsoft.com/kernel"
    version="1.0">

  <xsl:output
      method="html"
      omit-xml-declaration="yes"
      indent="no"
      encoding="utf-16" />

  <xsl:variable name="reportInfo" select="/bat:BatteryReport/bat:ReportInformation" />
  <xsl:variable name="systemInfo" select="/bat:BatteryReport/bat:SystemInformation" />
  <xsl:variable name="reportTime" select="string($reportInfo/bat:ScanTime)" />
  <xsl:variable name="localReportTime" select="string($reportInfo/bat:LocalScanTime)" />
  <xsl:variable name="aoac" select="$systemInfo/bat:ConnectedStandby != 0" />
  <xsl:variable name="reportDuration" select="$reportInfo/bat:ReportDuration" />
  <xsl:variable name="graphStart" select="$reportInfo/bat:LocalReportStartTime" />

  <!-- Creates the name of the state of a bat:UsageEntry -->
  <xsl:template match="bat:UsageEntry" mode ="toStateName" >
    <xsl:choose>
      <xsl:when test="@EntryType = 'Suspend'">
        Suspended
      </xsl:when>
      <xsl:when test="@EntryType = 'Active'">
        Active
      </xsl:when>
      <xsl:when test="@EntryType = 'ReportGenerated'">
        Report generated
      </xsl:when>
      <xsl:when test="@EntryType = 'BatteryChanged'">
        Battery changed
      </xsl:when>

      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$aoac">
            Connected standby
          </xsl:when>
          <xsl:otherwise>
            Screen off
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


  <!-- Creates the name of the power source of a bat:UsageEntry -->
  <xsl:template match="bat:UsageEntry" mode ="toPowerSourceName" >
    <xsl:choose>
      <xsl:when test="@EntryType = 'Suspend'">
      </xsl:when>
      <xsl:when test="@Ac = '0'">
        Battery
      </xsl:when>
      <xsl:otherwise>
        AC
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


  <!-- Creates the "even" or "odd" class for rows. This is used to give the rows alternating colors. -->
  <xsl:template name="classEvenOdd" >
    <xsl:param name="position" />
    <xsl:param name="otherClasses" select="''" />
    <xsl:attribute name="class">
      <xsl:choose>
        <xsl:when test="$position mod 2">even</xsl:when>
        <xsl:otherwise>odd</xsl:otherwise>
      </xsl:choose>
      <xsl:text> </xsl:text>
      <xsl:value-of select="$otherClasses" />
      <xsl:text> </xsl:text>
      <xsl:value-of select="$position" />
    </xsl:attribute>
  </xsl:template>


  <!-- Styles -->
  <xsl:template name="css">
    <style type="text/css">
      body {
          font-family: Segoe UI Light;
          letter-spacing: 0.02em;
          background-color: #181818;
          color: #F0F0F0;
          margin-left: 5.5em;
      }

      h1 {
          color: #11D8E8;
          font-size: 42pt;
      }

      h2 {
          font-size: 15pt;
          color: #11EEF4;
          margin-top: 4em;
          margin-bottom: 0em;
          letter-spacing: 0.08em;
      }

      td {
          padding-left: 0.3em;
          padding-right: 0.3em;
      }

      .nobatts {
          font-family: Segoe UI Semibold;
          background: #272727;
          color: #ACAC60;
          font-size: 13pt;
          padding-left:0.4em;
          padding-right:0.4em;
          padding-top:0.3em;
          padding-bottom:0.3em;
      }

      .explanation {
          color: #777777;
          font-size: 12pt;
          margin-bottom: 1em;
      }

      .explanation2 {
          color: #777777;
          font-size: 12pt;
          margin-bottom: 0.1em;
      }

      table {
          border-width: 0;
          table-layout: fixed;
          font-family: Segoe UI Light;
          letter-spacing: 0.02em;
          background-color: #181818;
          color: #f0f0f0;
      }

      .even { background: #272727; }
      .odd { background: #1E1E1E; }
      .even.suspend { background: #1A1A28; }
      .odd.suspend { background: #1A1A2C; }

      thead {
          font-family: Segoe UI Semibold;
          font-size: 85%;
          color: #BCBCBC;
      }

      text {
          font-size: 12pt;
          font-family: Segoe UI Light;
          fill: #11EEF4;
      }

      .centered { text-align: center; }

      .label {
          font-family: Segoe UI Semibold;
          font-size: 85%;
          color: #BCBCBC;
      }

      .dc.even { background: #40182C; }
      .dc.odd { background: #30141F; }

      td.colBreak {
          padding: 0;
          width: 0.15em;
      }

      td.state { text-align: center; }

      td.hms {
          font-family: Segoe UI Symbol;
          text-align: right;
          padding-right: 3.4em;
      }

      td.dateTime { font-family: Segoe UI Symbol; }
      td.nullValue { text-align: center; }

      td.percent {
          font-family: Segoe UI Symbol;
          text-align: right;
          padding-right: 2.5em;
      }

      col:first-child { width: 13em; }
      col.col2 { width: 10.4em; }
      col.percent { width: 7.5em; }

      td.mw {
          text-align: right;
          padding-right: 2.5em;
      }

      td.acdc { text-align: center; }

      span.date {
          display: inline-block;
          width: 5.5em;
      }

      span.time {
          text-align: right;
          width: 4.2em;
          display: inline-block;
      }

      text { font-family: Segoe UI Symbol; }

      .noncontigbreak {
          height: 0.3em;
          background-color: #1A1A28;
      }
    </style>
  </xsl:template>

  <xsl:template name="jsDateUtil">
    <xsl:text disable-output-escaping="yes">
    // Formats a number using the current locale (to handle the 1000's separator).
    // The result is rounded so no decimal point is shown.
    function numberToLocaleString(value) {
        var localeString = Math.round(parseFloat(value + '')).toLocaleString();
        return localeString.substring(0, localeString.indexOf('.'));
    }

    function padLeft(number, length) {
        var str = '' + number;
        while (str.length &lt; length) {
            str = '0' + str;
        }

        return str;
    }

    // Returns the number of milliseconds between 2 date-times represented as strings.
    function msBetween(startTime, endTime) {
        return startTime &gt; endTime
               ? msBetween(endTime, startTime)
               : parseDateTime(endTime) - parseDateTime(startTime);
    }

    var dateFormat = /(\d{4})-(\d{2})-(\d{2})[T](\d{2}):(\d{2}):(\d{2})/

    // Parses a date-time string and returns a Date (i.e. number of milliseconds)
    function parseDateTime(value) {
        if (!value) {
            return 0;
        }

        var match = dateFormat.exec(value)
        if (!match) {
            return 0;
        }

        return Date.parse(match[1] + '/' + match[2] + '/' +
                          match[3] + ' ' + match[4] + ':' +
                          match[5] + ':' + match[6])
    }

    // Parses just the date portion of a date-time string and returns a Date
    // (i.e. number of milliseconds)
    function parseDate(value) {
        if (!value) {
            return 0;
        }

        var match = dateFormat.exec(value)
        if (!match) {
            return 0;
        }

        return Date.parse(match[1] + '/' + match[2] + '/' + match[3])
    }

    var durationFormat = /P((\d+)D)?T((\d+)H)?((\d+)M)?(\d+)S/

    // Convert a string of the form P10DT1H15M40S to a count of milliseconds
    function parseDurationToMs(value) {
        var match = durationFormat.exec(value)
        if (!match) {
            return 0
        }

        var days = parseInt(match[2] || '0');
        var hrs = parseInt(match[4] || '0');
        var mins = parseInt(match[6] || '0');
        var secs = parseInt(match[7] || '0');
        return ((((((days * 24) + hrs) * 60) + mins) * 60) +  secs) * 1000;
    }

    // Converts milliseconds to days
    function msToDays(ms) {
        return (ms / 1000 / 60 / 60 / 24);
    }

    function daysToMs(days) {
        return (days * 24 * 60 * 60 * 1000);
    }

    // Formats a number of milliseconds as h:mm:ss
    function formatDurationMs(value) {
        var ms = parseInt(value);
        var secs = ms / 1000;
        var mins = secs / 60;
        var hrs = Math.floor(mins / 60);
        mins = Math.floor(mins % 60);
        secs = Math.floor(secs % 60);
        return hrs + ':' + padLeft(mins,2) + ':' + padLeft(secs,2);
    }

    // Converts a millisecond timestamp to a day and month string
    // Note: dayOffset is forward from date.
    function dateToDayAndMonth(ms, dayOffset) {
        var adjustedDate = new Date(ms + (dayOffset * 24 * 60 * 60 * 1000));
        return padLeft(adjustedDate.getMonth() + 1, 2) + "-" +
               padLeft(adjustedDate.getDate(), 2);
    }

    // Takes a millisecond timestamp and returns a new millisecond timestamp
    // rounded down to the current day.
    function dateFloor(ms) {
        var dt = new Date(ms);
        return Date.parse(dt.getFullYear() + '/' + (dt.getMonth() + 1) + '/' + dt.getDate());
    }
    </xsl:text>
  </xsl:template>

  <xsl:template name="jsTimegraph">
    <xsl:text disable-output-escaping="yes">
    Timegraph = {
        axisTop: 9.5,
        axisRight: 24.5,
        axisBottom: 25.5,
        axisLeft: 25.5,
        ticks: 10,

        // Maximum number of 24 hour ticks for showing 12 and 6 hour ticks

        ticks12Hour: 8,
        ticks6Hour: 4,

        // Shading

        lineColor: "#B82830",
        shadingColor: "#4d1d35",

        precompute: function (graph) {
            var canvas = graph.canvas;
            var data = graph.data;
            var min = 0;
            var max = 0;

            graph.height = canvas.height - Timegraph.axisTop - Timegraph.axisBottom;
            graph.width = canvas.width - Timegraph.axisLeft - Timegraph.axisRight;
            for (var i = 0; i &lt; data.length; i++) {
                data[i].t0 = parseDateTime(data[i].x0);
                data[i].t1 = parseDateTime(data[i].x1);

                if (i == 0) {
                    min = data[i].t0;
                    max = data[i].t1;
                }

                if (data[i].t0 &lt; min) {
                    min = data[i].t0;
                }

                if (data[i].t1 &gt; max) {
                    max = data[i].t1;
                }

                data[i].yy0 =
                    Timegraph.axisTop + graph.height - data[i].y0 * graph.height;

                data[i].yy1 =
                    Timegraph.axisTop + graph.height - data[i].y1 * graph.height;
            }

            if (graph.startTime != null) {
                graph.startMs = parseDateTime(graph.startTime);

            } else {
                graph.startMs = min;
            }

            graph.endMs = max;
            graph.durationMs = max - min;
        },

        drawFrame: function (graph) {
            var canvas = graph.canvas;
            var context = graph.context;

            graph.width =
                canvas.width - Timegraph.axisRight - Timegraph.axisLeft;

            graph.height =
                canvas.height - Timegraph.axisTop - Timegraph.axisBottom;

            context.beginPath();
            context.moveTo(Timegraph.axisLeft, Timegraph.axisTop);
            context.lineTo(Timegraph.axisLeft + graph.width,
                           Timegraph.axisTop);

            context.lineTo(Timegraph.axisLeft + graph.width,
                           Timegraph.axisTop + graph.height);

            context.lineTo(Timegraph.axisLeft,
                           Timegraph.axisTop + graph.height);

            context.lineTo(Timegraph.axisLeft, Timegraph.axisTop);
            context.strokeStyle = "#c0c0c0";
            context.stroke();
        },

        drawRange: function (graph) {
            var canvas = graph.canvas;
            var context = graph.context;

            context.font = "12pt Segoe UI";
            context.fillStyle = "#00b0f0";
            context.fillText("%", 0, Timegraph.axisTop + 5, Timegraph.axisLeft);

            var tickSpacing = graph.height / 10;
            var offset = Timegraph.axisTop + tickSpacing;
            var tickValue = 90;
            for (var i = 0; i &lt; 9; i++) {
                context.beginPath();
                context.moveTo(Timegraph.axisLeft, offset);
                context.lineTo(Timegraph.axisLeft + graph.width,
                               offset);

                context.stroke();
                context.fillText(tickValue.toString(),
                                 0,
                                 offset + 5,
                                 Timegraph.axisLeft);

                offset += tickSpacing;
                tickValue -= 10;
            }
        },

        drawDomain: function (graph, start, end) {
            var canvas = graph.canvas;
            var context = graph.context;
            var data = graph.data;
            var duration = end - start;
            if ((end &lt; start)) {
                return;
            }

            var startDay = dateFloor(start);
            var t0 = startDay;
            var t1 = dateFloor(end);
            var dayOffset = 0;
            if (start &gt; t0) {
                t0 = t0 + daysToMs(1);
                dayOffset++;
            }

            if (t0 &gt;= t1) {
                return;
            }

            var increment =
                Math.max(Math.floor((t1 - t0) / daysToMs(Timegraph.ticks)), 1);

            var incrementMs = daysToMs(increment);
            var spacing = (incrementMs / duration) * graph.width;
            var offset = (t0 - start) / duration;
            var ticksCount = Math.floor((t1 - t0) / incrementMs);
            for (offset = offset * graph.width + Timegraph.axisLeft;
                 offset &lt; (graph.width + Timegraph.axisLeft);
                 offset += spacing) {

                context.beginPath();
                context.moveTo(offset, Timegraph.axisTop);
                context.lineTo(offset, Timegraph.axisTop + graph.height);
                context.stroke();
                context.fillText(dateToDayAndMonth(startDay, dayOffset),
                                 offset,
                                 Timegraph.axisTop + graph.height + 15,
                                 spacing);

                dayOffset += increment;
            }
        },

        plot: function (graph, start, end) {
            var canvas = graph.canvas;
            var context = graph.context
            var data = graph.data;

            if ((end &lt; start)) {
                return;
            }

            var duration = end - start;
            Timegraph.drawDomain(graph, start, end);
            context.fillStyle = Timegraph.shadingColor;
            for (var i = 0; i &lt; data.length - 1; i++) {
                if ((data[i].t0 &lt; start) || (data[i].t0 &gt; end) ||
                    (data[i].t1 &gt; end)) {

                    continue;
                }

                var x1 = (data[i].t0 - start) / duration;
                x1 = x1 * graph.width + Timegraph.axisLeft;

                var x2 = (data[i].t1 - start) / duration;
                x2 = x2 * graph.width + Timegraph.axisLeft;

                context.globalAlpha = 0.3;
                context.fillRect(x1, Timegraph.axisTop, (x2 - x1), graph.height);
                context.globalAlpha = 1;
                context.beginPath();
                context.strokeStyle = Timegraph.lineColor;
                context.lineWidth = 1.5;
                context.moveTo(x1, data[i].yy0);
                context.lineTo(x2, data[i].yy1);
                context.stroke();
            }
        },

        draw: function (graph) {
            var canvas = document.getElementById(graph.element);
            if (canvas == null) {
                return;
            }

            var context = canvas.getContext('2d');
            if (context == null) {
                return;
            }

            graph.width = 0;
            graph.height = 0;
            graph.context = context;
            graph.canvas = canvas;

            Timegraph.precompute(graph);
            Timegraph.drawFrame(graph);
            Timegraph.drawRange(graph);
            Timegraph.plot(graph, graph.startMs, graph.endMs);
        }
    };
    </xsl:text>
  </xsl:template>

  <xsl:template name="javascript">
    <xsl:param name="energyDrains" />

    <script type="text/javascript">
    <xsl:call-template name="jsDateUtil" />
    <xsl:call-template name="jsTimegraph" />

    <xsl:apply-templates select="$energyDrains" mode="jsEnergyDrains" />

    <xsl:text disable-output-escaping="yes">
    function main() {
        Timegraph.draw({
            element: "drain-graph",
            data: drainGraphData,
            startTime: "</xsl:text><xsl:value-of select="$graphStart" /><xsl:text disable-output-escaping="yes">",
            endTime: "</xsl:text><xsl:value-of select="$reportInfo/bat:LocalScanTime" /><xsl:text disable-output-escaping="yes">",
        });
    }

    if (window.addEventListener != null) {
        window.addEventListener("load", main, false);

    } else if (window.attachEvent != null) {
        window.attachEvent("onload", main);
    }
    </xsl:text>
    </script>
  </xsl:template>

  <xsl:template match="bat:Drain" mode="jsEnergyDrains">
    <xsl:text>{ </xsl:text>
    <xsl:text>x0: "</xsl:text><xsl:value-of select="@LocalStartTimestamp" /><xsl:text>", </xsl:text>
    <xsl:text>x1: "</xsl:text><xsl:value-of select="@LocalEndTimestamp" /><xsl:text>", </xsl:text>
    <xsl:text>y0: </xsl:text><xsl:value-of select="@StartChargeCapacity div @StartFullChargeCapacity" /><xsl:text>, </xsl:text>
    <xsl:text>y1: </xsl:text><xsl:value-of select="@EndChargeCapacity div @EndFullChargeCapacity" /><xsl:text> </xsl:text>
    <xsl:text>}, &#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="bat:EnergyDrains" mode="jsEnergyDrains">
    <xsl:text>
    drainGraphData = [
    </xsl:text>
    <xsl:apply-templates select="bat:Drain" mode="jsEnergyDrains" />
    <xsl:text>
    ];
    </xsl:text>
  </xsl:template>

  <!-- The top section of the report. Gives information about the system. -->
  <xsl:template name="header">
    <h1>
      Battery report
    </h1>
    <table style="margin-bottom: 6em;">
      <col />
      <tr>
        <td class="label">
          COMPUTER NAME
        </td>
        <td>
          <xsl:value-of select="$systemInfo/bat:ComputerName" />
        </td>
      </tr>
      <tr>
        <td class="label">
          SYSTEM PRODUCT NAME
        </td>
        <td>
          <xsl:value-of select="$systemInfo/bat:SystemManufacturer" />
          <xsl:text> </xsl:text>
          <xsl:value-of select="$systemInfo/bat:SystemProductName" />
        </td>
      </tr>
      <tr>
        <td class="label">
          BIOS
        </td>
        <td>
          <xsl:value-of select="$systemInfo/bat:BIOSVersion" />
          <xsl:text> </xsl:text>
          <xsl:value-of select="$systemInfo/bat:BIOSDate" />
        </td>
      </tr>
      <tr>
        <td class="label">
          OS BUILD
        </td>
        <td>
          <xsl:value-of select="$systemInfo/bat:OSBuild" />
        </td>
      </tr>
      <tr>
        <td class="label">
          PLATFORM ROLE
        </td>
        <td>
          <xsl:value-of select="$systemInfo/bat:PlatformRole" />
        </td>
      </tr>
      <tr>
        <td class="label">
          CONNECTED STANDBY
        </td>
        <td>
          <xsl:choose>
            <xsl:when test="$aoac">
              <xsl:text>Supported</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>Not supported</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </td>
      </tr>
      <tr>
        <td class="label">
          REPORT TIME
        </td>
        <td class="dateTime">
          <xsl:call-template name="formatDateTime">
            <xsl:with-param name="dateTime" select="$localReportTime" />
          </xsl:call-template>
        </td>
      </tr>
    </table>
  </xsl:template>

  <!-- The list of installed batteries -->
  <xsl:template match="bat:Batteries" >
    <!-- Only look at "long term" batteries (i.e. not UPS batteries) -->
    <xsl:variable name="longTermBatts" select="bat:Battery[bat:LongTerm != 0]" />

    <h2>
      Installed batteries
    </h2>
    <div class="explanation">
      Information about each currently installed battery
    </div>

    <xsl:choose>
      <xsl:when test="count($longTermBatts) = 0">
        <!-- No batteries currently installed -->
        <div style="margin-top:1.5em;">
          <span class="nobatts">No batteries are currently installed</span>
        </div>
      </xsl:when>
      <xsl:otherwise>
        <table>
          <colgroup>
            <col style="width: 15em;" />
            <xsl:for-each select="$longTermBatts">
              <col style="width: 14em;" />
            </xsl:for-each>
          </colgroup>
          <thead>
            <tr>
              <td>
                <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
                <xsl:text> </xsl:text>
              </td>
              <xsl:for-each select="$longTermBatts">
                <td>
                  BATTERY
                  <xsl:value-of select="position()"/>
                </td>
              </xsl:for-each>
            </tr>
          </thead>
          <tr>
            <td>
              <span class="label">NAME</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:call-template name="dashIfEmpty">
                  <xsl:with-param name="str" select="bat:Id"/>
                </xsl:call-template>
              </td>
            </xsl:for-each>
          </tr>
          <tr>
            <td>
              <span class="label">MANUFACTURER</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:call-template name="dashIfEmpty">
                  <xsl:with-param name="str" select="bat:Manufacturer"/>
                </xsl:call-template>
              </td>
            </xsl:for-each>
          </tr>
          <tr>
            <td>
              <span class="label">SERIAL NUMBER</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:call-template name="dashIfEmpty">
                  <xsl:with-param name="str" select="bat:SerialNumber"/>
                </xsl:call-template>
              </td>
            </xsl:for-each>
          </tr>
          <tr>
            <td>
              <span class="label">CHEMISTRY</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:call-template name="dashIfEmpty">
                  <xsl:with-param name="str" select="bat:Chemistry"/>
                </xsl:call-template>
              </td>
            </xsl:for-each>
          </tr>
          <tr>
            <td>
              <span class="label">DESIGN CAPACITY</span>
            </td>

            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:choose>
                  <!-- If RelativeCapacity=1, the units reported for the battery are not mWh -->
                  <xsl:when test="bat:RelativeCapacity = 1">
                    -
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:call-template name="mWh">
                      <xsl:with-param name="value" select="bat:DesignCapacity"/>
                    </xsl:call-template>
                  </xsl:otherwise>
                </xsl:choose>
              </td>
            </xsl:for-each>
          </tr>

          <!-- Small break to hint that the next 2 values are special (they can change over time) -->
          <tr style="height:0.4em;"></tr>

          <tr>
            <td>
              <span class="label">FULL CHARGE CAPACITY</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:choose>
                  <!-- If RelativeCapacity=1, the units reported for the battery are not mWh -->
                  <xsl:when test="bat:RelativeCapacity = 1">
                    -
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:call-template name="mWh">
                      <xsl:with-param name="value" select="bat:FullChargeCapacity"/>
                    </xsl:call-template>
                  </xsl:otherwise>
                </xsl:choose>
              </td>
            </xsl:for-each>
          </tr>
          <tr>
            <td>
              <span class="label">CYCLE COUNT</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:call-template name="dashIfEmpty">
                  <xsl:with-param name="str" select="bat:CycleCount"/>
                </xsl:call-template>
              </td>
            </xsl:for-each>
          </tr>
        </table>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="bat:RecentUsage" mode="recentUsage">
    <h2>Recent usage</h2>
    <div class="explanation">
      Power states over the last <xsl:value-of select="$reportDuration" /> days
    </div>
    <table>
      <colgroup>
        <col />
        <col class="col2" />
        <col style="width: 4.2em;" />
        <col class="percent" />
        <col style="width: 11em;" />
      </colgroup>
      <thead>
        <tr>
          <td>
            START TIME
          </td>
          <td class="centered">
            STATE
          </td>
          <td class="centered">
            SOURCE
          </td>
          <td colspan="2"  class="centered">
            CAPACITY REMAINING
          </td>
        </tr>
      </thead>

      <xsl:choose>
        <xsl:when test="count(bat:UsageEntry)">
          <xsl:apply-templates select="bat:UsageEntry" mode="recentUsage"  />
        </xsl:when>
        <xsl:otherwise>
          <!-- No data. Show one line of dashes -->
          <tr class="even">
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
          </tr>
        </xsl:otherwise>
      </xsl:choose>

    </table>
  </xsl:template>

  <xsl:template match="bat:UsageEntry" mode="recentUsage">
    <tr>
      <xsl:choose>
        <xsl:when test="@BatteryChanged != 0">
          <xsl:call-template name="classEvenOdd">
            <xsl:with-param name="position" select="position()"/>
            <xsl:with-param name="otherClasses" select="'batt'"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="@EntryType = 'Suspend'">
          <xsl:call-template name="classEvenOdd">
            <xsl:with-param name="position" select="position()" />
            <xsl:with-param name="otherClasses" select="'suspend'" />
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="@Ac = 0">
          <xsl:call-template name="classEvenOdd">
            <xsl:with-param name="position" select="position()" />
            <xsl:with-param name="otherClasses" select="'dc'" />
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="classEvenOdd">
            <xsl:with-param name="position" select="position()" />
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>

      <td class="dateTime">
        <xsl:call-template name="formatDateTime">
          <xsl:with-param name="dateTime" select="@LocalTimestamp" />
          <xsl:with-param name="showDate" select ="js:parseDate(string(@LocalTimestamp)) != js:parseDate(string(preceding-sibling::*[1]/@LocalTimestamp))" />
        </xsl:call-template>
      </td>
      <td class="state">
        <xsl:apply-templates mode="toStateName" select="." />
      </td>
      <td class="acdc">
        <xsl:apply-templates mode="toPowerSourceName" select="." />
      </td>

      <!-- Capacity remaining -->
      <xsl:call-template name="percentCell">
        <xsl:with-param name="value" select="round(100 * @ChargeCapacity div @FullChargeCapacity)" />
      </xsl:call-template>

      <xsl:call-template name="mWhCell">
        <xsl:with-param name="value" select="@ChargeCapacity" />
      </xsl:call-template>

    </tr>
  </xsl:template>

  <xsl:template match="bat:EnergyDrains" mode="energyDrainGraph">
    <h2>Battery usage</h2>
    <div class="explanation">
      Battery drains over the last <xsl:value-of select="$reportDuration" /> days
    </div>

    <canvas id="drain-graph" width="864" height="400"></canvas>
  </xsl:template>

  <xsl:template match="bat:RecentUsage" mode="batteryUsage">
    <table>
      <colgroup>
        <col/>
        <col class="col2" />
        <col style="width: 10em;" />
        <col class="percent" />
        <col style="width: 11em;" />
      </colgroup>
      <thead>
        <tr>
          <td>
            START TIME
          </td>
          <td class="centered">
            STATE
          </td>
          <td class="centered">
            DURATION
          </td>
          <td class="centered" colspan="2">
            ENERGY DRAINED
          </td>
        </tr>
      </thead>

      <xsl:variable name="batteryUsageEntries" select="bat:UsageEntry[@Ac = '0' and (@EntryType = 'Active' or @EntryType = 'ConnectedStandby')]" />

      <xsl:choose>
        <xsl:when test="count(ms:node-set($batteryUsageEntries))">
          <xsl:apply-templates select="ms:node-set($batteryUsageEntries)" mode="batteryUsage"  />
        </xsl:when>
        <xsl:otherwise>
          <!-- No data. Show one line of dashes -->
          <tr class="even">
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
          </tr>
        </xsl:otherwise>
      </xsl:choose>

    </table>
  </xsl:template>

  <!-- Outputs the "Battery usage" table contents -->
  <xsl:template match="bat:UsageEntry" mode="batteryUsage">
    <tr>
      <xsl:call-template name="classEvenOdd">
        <xsl:with-param name="position" select="position()" />
        <xsl:with-param name="otherClasses" select="'dc'" />
      </xsl:call-template>
      <td class="dateTime">
        <xsl:call-template name="formatDateTime">
          <xsl:with-param name="dateTime" select="@LocalTimestamp" />
          <xsl:with-param name="showDate" select ="js:parseDate(string(@LocalTimestamp)) != js:parseDate(string(preceding-sibling::*[1]/@LocalTimestamp)) or position() = '1'" />
        </xsl:call-template>
      </td>
      <td class="state">
        <xsl:apply-templates mode="toStateName" select="." />
      </td>
      <td class="hms">
        <xsl:value-of select="js:formatDurationMs(string(@Duration div 10000))" />
      </td>

      <!-- Energy drained -->
      <xsl:call-template name="percentCell">
        <xsl:with-param name="value" select="round(100 * @Discharge div @FullChargeCapacity)" />
      </xsl:call-template>

      <xsl:call-template name="mWhCell">
        <xsl:with-param name="value" select="@Discharge" />
      </xsl:call-template>

    </tr>

    <!-- If the next entry is not running on batteries, include a small gap to make apparent that the usage
         isn't contiguous. -->
    <xsl:if test="position() != last() and @IsNextOnBattery != '1'">
      <tr class="noncontigbreak">
        <td colspan="5">
          <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
          <xsl:text> </xsl:text>
        </td>
      </tr>
    </xsl:if>
  </xsl:template>

  <!-- Outputs the Usage history report -->
  <xsl:template match="/bat:BatteryReport/bat:History" mode="usageHistory">
    <h2>
      Usage history
    </h2>
    <div class="explanation2">
      History of system usage on AC and battery
    </div>
    <table>
      <colgroup>
        <col/>
        <col class="col2" />
        <col style="width: 10em;" />
        <col style="" />
        <col style="width: 10em;" />
        <col style="width: 10em;" />
        <col style="" />
      </colgroup>
      <thead>
        <tr>
          <td>
            <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
            <xsl:text> </xsl:text>
          </td>
          <td colspan="2" class="centered">
            BATTERY DURATION
          </td>

          <!-- Break between columns -->
          <td class="colBreak" >
            <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
            <xsl:text> </xsl:text>
          </td>

          <td colspan="3" class="centered">
            AC DURATION
          </td>
        </tr>
        <tr>
          <td>
            PERIOD
          </td>
          <td class="centered">
            ACTIVE
          </td>
          <td class="centered">
            CONNECTED STANDBY
          </td>

          <!-- Break between columns -->
          <td class="colBreak" >
            <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
            <xsl:text> </xsl:text>
          </td>

          <td class="centered">
            ACTIVE
          </td>
          <td class="centered">
            CONNECTED STANDBY
          </td>
        </tr>
      </thead>

      <xsl:choose>
        <xsl:when test="count(bat:HistoryEntry)">
          <xsl:apply-templates select="bat:HistoryEntry" mode="usageHistory" />
        </xsl:when>
        <xsl:otherwise>
          <!-- No data. Show one line of dashes -->
          <tr class="even">
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <!-- Break between columns -->
            <td class="colBreak" >
              <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
              <xsl:text> </xsl:text>
            </td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
          </tr>
        </xsl:otherwise>
      </xsl:choose>

    </table>
  </xsl:template>

  <!-- Outputs a date range as 2 dates if the dates are more than 24 hours apart, otherwise the start date only -->
  <xsl:template match="/bat:BatteryReport/bat:History/bat:HistoryEntry" mode="dateRange">
    <xsl:value-of select="substring-before(@LocalStartDate, 'T')" />
    <xsl:if test="js:msBetween(string(@LocalStartDate), string(@LocalEndDate)) > (24 * 60 * 60 * 1000)">
      - <xsl:value-of select="substring-before(@LocalEndDate, 'T')" />
    </xsl:if>
  </xsl:template>

  <!-- Outputs a row in the Usage history report -->
  <xsl:template match="/bat:BatteryReport/bat:History/bat:HistoryEntry" mode="usageHistory">
    <tr>
      <xsl:call-template name="classEvenOdd">
        <xsl:with-param name="position" select="position()" />
      </xsl:call-template>
      <td class="dateTime">
        <xsl:apply-templates select="."  mode="dateRange" />
      </td>

      <xsl:variable name="ActiveDcTime" select="js:parseDurationToMs(string(@ActiveDcTime))" />
      <xsl:choose>
        <xsl:when test="$ActiveDcTime = 0">
          <td class="nullValue">-</td>
        </xsl:when>
        <xsl:otherwise>
          <td class="hms">
            <xsl:value-of select="js:formatDurationMs($ActiveDcTime)"/>
          </td>
        </xsl:otherwise>
      </xsl:choose>

      <xsl:variable name="CsDcTime" select="js:parseDurationToMs(string(@CsDcTime))" />
      <xsl:choose>
        <xsl:when test="$CsDcTime = 0">
          <td class="nullValue">-</td>
        </xsl:when>
        <xsl:otherwise>
          <td class="hms">
            <xsl:value-of select="js:formatDurationMs($CsDcTime)"/>
          </td>
        </xsl:otherwise>
      </xsl:choose>

      <!-- Break between columns -->
      <td class="colBreak" >
        <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
        <xsl:text> </xsl:text>
      </td>

      <xsl:variable name="ActiveAcTime" select="js:parseDurationToMs(string(@ActiveAcTime))" />
      <xsl:choose>
        <xsl:when test="$ActiveAcTime = 0">
          <td class="nullValue">-</td>
        </xsl:when>
        <xsl:otherwise>
          <td class="hms">
            <xsl:value-of select="js:formatDurationMs($ActiveAcTime)"/>
          </td>
        </xsl:otherwise>
      </xsl:choose>

      <xsl:variable name="CsAcTime" select="js:parseDurationToMs(string(@CsAcTime))" />
      <xsl:choose>
        <xsl:when test="$CsAcTime = 0">
          <td class="nullValue">-</td>
        </xsl:when>
        <xsl:otherwise>
          <td class="hms">
            <xsl:value-of select="js:formatDurationMs($CsAcTime)"/>
          </td>
        </xsl:otherwise>
      </xsl:choose>

    </tr>
  </xsl:template>

  <xsl:template match="/bat:BatteryReport/bat:History" mode="batteryCapacityHistory">
    <h2>
      Battery capacity history
    </h2>
    <div class="explanation">
      Charge capacity history of the system's batteries
    </div>
    <table>
      <colgroup>
        <col/>
        <col class="col2"/>
        <col style="width: 10em;" />
      </colgroup>
      <thead>
        <tr>
          <td>
            <span>PERIOD</span>
          </td>
          <td class="centered">
            FULL CHARGE CAPACITY
          </td>
          <td class="centered">
            DESIGN CAPACITY
          </td>
        </tr>
      </thead>


      <xsl:choose>
        <xsl:when test="count(bat:HistoryEntry)">
          <xsl:apply-templates select="bat:HistoryEntry" mode="batteryCapacityHistory" />
        </xsl:when>
        <xsl:otherwise>
          <!-- No data. Show one line of dashes -->
          <tr class="even">
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
          </tr>
        </xsl:otherwise>
      </xsl:choose>

    </table>
  </xsl:template>

  <!-- Outputs a row in the Battery capacity history report -->
  <xsl:template match="/bat:BatteryReport/bat:History/bat:HistoryEntry" mode="batteryCapacityHistory">
    <tr>
      <xsl:call-template name="classEvenOdd">
        <xsl:with-param name="position" select="position()" />
      </xsl:call-template>
      <td class="dateTime">
        <xsl:apply-templates select="."  mode="dateRange" />
      </td>
      <xsl:call-template name="mWhCell">
        <xsl:with-param name="value" select="@FullChargeCapacity"/>
      </xsl:call-template>
      <xsl:call-template name="mWhCell">
        <xsl:with-param name="value" select="@DesignCapacity"/>
      </xsl:call-template>
    </tr>
  </xsl:template>

  <!-- Outputs the Battery life estimates report -->
  <xsl:template match="/bat:BatteryReport/bat:History" mode="batteryLifeEstimates">
    <h2>
      Battery life estimates
    </h2>
    <div class="explanation2">
      Battery life estimates based on observed drains
    </div>
    <table>
      <colgroup>
        <col/>
        <col class="col2"/>
        <col style="width: 10em;" />
        <col style="" />
        <col style="width: 10em;" />
        <col style="width: 10em;" />
        <col style="width: 10em;" />
      </colgroup>
      <thead>
        <tr class="rowHeader">
          <td>
            <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
            <xsl:text> </xsl:text>
          </td>
          <td colspan="2" class="centered">
            AT FULL CHARGE
          </td>

          <!-- Break between columns -->
          <td class="colBreak" >
            <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
            <xsl:text> </xsl:text>
          </td>

          <td colspan="2" class="centered">
            AT DESIGN CAPACITY
          </td>
        </tr>
        <tr class="rowHeader">
          <td>
            PERIOD
          </td>
          <td class="centered">
            <span>ACTIVE</span>
          </td>
          <td class="centered">
            <span>CONNECTED STANDBY</span>
          </td>

          <!-- Break between columns -->
          <td class="colBreak" >
            <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
            <xsl:text> </xsl:text>
          </td>

          <td class="centered">
            <span>ACTIVE</span>
          </td>
          <td class="centered">
            <span>CONNECTED STANDBY</span>
          </td>
        </tr>
      </thead>

      <xsl:choose>
        <xsl:when test="count(bat:HistoryEntry)">
          <xsl:apply-templates select="bat:HistoryEntry" mode="batteryLifeEstimates" />
        </xsl:when>
        <xsl:otherwise>
          <!-- No data. Show one line of dashes -->
          <tr class="even">
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <!-- Break between columns -->
            <td class="colBreak" >
              <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
              <xsl:text> </xsl:text>
            </td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
          </tr>
        </xsl:otherwise>
      </xsl:choose>

    </table>
    <div class="explanation2" style="margin-top: 1em; margin-bottom: 0.4em;">
      Current estimate of battery life based on all observed drains since OS install
    </div>
    <table >
      <colgroup>
        <col />
        <col class="col2"/>
        <col style="width: 10em;" />
        <col style="" />
        <col style="width: 10em;" />
        <col style="width: 10em;" />
        <col style="width: 10em;" />
      </colgroup>
      <tr class="even"  style="vertical-align:top">
        <td>
          Since OS install
        </td>
        <xsl:variable name="runtimeEstimates" select="/bat:BatteryReport/bat:RuntimeEstimates"/>
        <xsl:variable name="fullChargeActiveRuntimeEstimate" select="js:parseDurationToMs(string($runtimeEstimates/bat:FullChargeCapacity/bat:ActiveRuntime))" />
        <xsl:variable name="fullChargeConnectedStandbyRuntimeEstimate" select="js:parseDurationToMs(string($runtimeEstimates/bat:FullChargeCapacity/bat:ConnectedStandbyRuntime))" />
        <xsl:variable name="designActiveRuntimeEstimate" select="js:parseDurationToMs(string($runtimeEstimates/bat:DesignCapacity/bat:ActiveRuntime))" />
        <xsl:variable name="designConnectedStandbyRuntimeEstimate" select="js:parseDurationToMs(string($runtimeEstimates/bat:DesignCapacity/bat:ConnectedStandbyRuntime))" />

        <xsl:choose>
          <xsl:when test="$fullChargeActiveRuntimeEstimate = 0">
            <td class="nullValue">-</td>
          </xsl:when>
          <xsl:otherwise>
            <td class="hms">
              <xsl:value-of select="js:formatDurationMs($fullChargeActiveRuntimeEstimate)"/>
            </td>
          </xsl:otherwise>
        </xsl:choose>

        <xsl:choose>
          <xsl:when test="$fullChargeConnectedStandbyRuntimeEstimate = 0">
            <td class="nullValue">-</td>
          </xsl:when>
          <xsl:otherwise>
            <td class="hms">
              <div style="height:1em;">
                <xsl:value-of select="js:formatDurationMs($fullChargeConnectedStandbyRuntimeEstimate)"/>
              </div>
              <span style="font-size:9pt; ">
                <xsl:call-template name="percent">
                  <xsl:with-param name="value" select="round(5760000000 div $fullChargeConnectedStandbyRuntimeEstimate)" />
                </xsl:call-template>
                / 16 h
              </span>
            </td>
          </xsl:otherwise>
        </xsl:choose>

        <!-- Break between columns -->
        <td class="colBreak" >
          <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
          <xsl:text> </xsl:text>
        </td>

        <xsl:choose>
          <xsl:when test="$designActiveRuntimeEstimate = 0">
            <td class="nullValue">-</td>
          </xsl:when>
          <xsl:otherwise>
            <td class="hms">
              <xsl:value-of select="js:formatDurationMs($designActiveRuntimeEstimate)"/>
            </td>
          </xsl:otherwise>
        </xsl:choose>

        <xsl:choose>
          <xsl:when test="$designConnectedStandbyRuntimeEstimate= 0">
            <td class="nullValue">-</td>
          </xsl:when>
          <xsl:otherwise>
            <td class="hms">
              <div style="height:1em;">
                <xsl:value-of select="js:formatDurationMs($designConnectedStandbyRuntimeEstimate)"/>
              </div>
              <span style="font-size:9pt; ">
                <xsl:call-template name="percent">
                  <xsl:with-param name="value" select="round(5760000000 div $designConnectedStandbyRuntimeEstimate)" />
                </xsl:call-template>
                / 16 h
              </span>
            </td>
          </xsl:otherwise>
        </xsl:choose>


      </tr>
    </table>
  </xsl:template>

  <!-- Outputs a row in the Battery life estimates report -->
  <xsl:template match="bat:HistoryEntry" mode="batteryLifeEstimates">

    <xsl:variable name="fullChargeActiveRuntimeEstimate" select="js:parseDurationToMs(string(@EstimatedFullChargeActiveTime))" />
    <xsl:variable name="fullChargeConnectedStandbyRuntimeEstimate" select="js:parseDurationToMs(string(@EstimatedFullChargeCsTime))" />
    <xsl:variable name="designActiveRuntimeEstimate" select="js:parseDurationToMs(string(@EstimatedDesignActiveTime))" />
    <xsl:variable name="designConnectedStandbyRuntimeEstimate" select="js:parseDurationToMs(string(@EstimatedDesignCsTime))" />


    <tr style="vertical-align:top">
      <xsl:call-template name="classEvenOdd">
        <xsl:with-param name="position" select="position()" />
      </xsl:call-template>
      <td class="dateTime">
        <xsl:apply-templates select="."  mode="dateRange" />
      </td>

      <xsl:choose>
        <xsl:when test="$fullChargeActiveRuntimeEstimate = 0">
          <td class="nullValue">-</td>
        </xsl:when>
        <xsl:otherwise>
          <td class="hms">
            <xsl:value-of select="js:formatDurationMs($fullChargeActiveRuntimeEstimate)"/>
          </td>
        </xsl:otherwise>
      </xsl:choose>

      <xsl:choose>
        <xsl:when test="$fullChargeConnectedStandbyRuntimeEstimate= 0">
          <td class="nullValue">-</td>
        </xsl:when>
        <xsl:otherwise>
          <td class="hms">
            <div style="height:1em;">
              <xsl:value-of select="js:formatDurationMs($fullChargeConnectedStandbyRuntimeEstimate)"/>
            </div>
            <span style="font-size:9pt; ">
              <xsl:call-template name="percent">
                <xsl:with-param name="value" select="round(5760000000 div $fullChargeConnectedStandbyRuntimeEstimate)" />
              </xsl:call-template>
              / 16 h
            </span>
          </td>
        </xsl:otherwise>
      </xsl:choose>

      <!-- Break between columns -->
      <td class="colBreak" >
        <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
        <xsl:text> </xsl:text>
      </td>


      <xsl:choose>
        <xsl:when test="$designActiveRuntimeEstimate = 0">
          <td class="nullValue">-</td>
        </xsl:when>
        <xsl:otherwise>
          <td class="hms">
            <xsl:value-of select="js:formatDurationMs($designActiveRuntimeEstimate)"/>
          </td>
        </xsl:otherwise>
      </xsl:choose>

      <xsl:choose>
        <xsl:when test="$designConnectedStandbyRuntimeEstimate= 0">
          <td class="nullValue">-</td>
        </xsl:when>
        <xsl:otherwise>
          <td class="hms">
            <div style="height:1em;">
              <xsl:value-of select="js:formatDurationMs($designConnectedStandbyRuntimeEstimate)"/>
            </div>
            <span style="font-size:9pt; ">
              <xsl:call-template name="percent">
                <xsl:with-param name="value" select="round(5760000000 div $designConnectedStandbyRuntimeEstimate)" />
              </xsl:call-template>
              / 16 h
            </span>
          </td>
        </xsl:otherwise>
      </xsl:choose>

    </tr>
  </xsl:template>


  <!-- Matches the root node. This starts the XSL processing. -->
  <xsl:template match="/" >
    <html>
      <head>
        <!-- Support the latest IE -->
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />

        <!-- All times are displayed using local time. Store the offset at which the report was generated in
             case someone needs to calculate the UTC times (although this is not entirely sufficient if the
             machine has moved timezones during the report period. -->
        <meta name="ReportUtcOffset" content="{$reportInfo/bat:UtcOffset}" />

        <title>Battery report</title>

        <!-- CSS styles -->
        <xsl:call-template name="css" />

        <!-- JavaScript -->
        <xsl:call-template name="javascript">
          <xsl:with-param name="energyDrains" select="/bat:BatteryReport/bat:EnergyDrains" />
        </xsl:call-template>
      </head>

      <body>

        <!-- Describe the machine -->
        <xsl:call-template name="header" />

        <!-- Installed batteries -->
        <xsl:apply-templates select="/bat:BatteryReport/bat:Batteries" />

        <!-- Recent usage-->
        <xsl:apply-templates select="/bat:BatteryReport/bat:RecentUsage" mode="recentUsage" />

        <!-- Usage Graph -->
        <xsl:apply-templates select="/bat:BatteryReport/bat:EnergyDrains" mode="energyDrainGraph" />

        <!-- Battery usage-->
        <xsl:apply-templates select="/bat:BatteryReport/bat:RecentUsage" mode="batteryUsage" />

        <xsl:variable name="history" select="/bat:BatteryReport/bat:History" />

        <!-- Usage history -->
        <xsl:apply-templates select="$history" mode="usageHistory" />

        <!-- Battery capacity history -->
        <xsl:apply-templates select="$history" mode="batteryCapacityHistory" />

        <!-- Battery life estimates -->
        <xsl:apply-templates select="$history" mode="batteryLifeEstimates" />
        <br />
        <br />
        <br />
      </body>
    </html>
  </xsl:template>

  <!-- Formats a date-time for display -->
  <xsl:template name="formatDateTime">
    <xsl:param name="dateTime"/>
    <xsl:param name="showDate" select="true()" />
    <xsl:variable name="date" select="substring-before($dateTime, 'T')"/>
    <xsl:variable name="time" select="translate(substring-after($dateTime, 'T'), 'T ', '')"/>

    <span class="date">
      <xsl:if test="$showDate">
        <xsl:value-of select="$date"/>
      </xsl:if>
      <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
      <xsl:text> </xsl:text>
    </span>
    <span class="time">
      <xsl:value-of select="$time"/>
    </span>
  </xsl:template>

  <!-- Outputs the given string, or a dash ('-') if the string is empty -->
  <xsl:template name="dashIfEmpty">
    <xsl:param name="str"/>
    <xsl:variable name="s" select="normalize-space($str)" />
    <xsl:choose>
      <xsl:when test="string-length($s) = 0">
        -
      </xsl:when>
      <xsl:when test="$s = '0'">
        -
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$s"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Formats a mWh value -->
  <xsl:template name="mWh">
    <xsl:param name="value"/>
    <xsl:variable name="number" select="number($value)" />
    <xsl:choose>
      <!-- Test for not NaN, not 0, and not Infinity -->
      <xsl:when test="$number != 0 and $number = $number and $number != (1 div 0) and $number != (-1 div 0)">
        <xsl:value-of select="js:numberToLocaleString($number)"/> mWh
      </xsl:when>
      <xsl:otherwise>
        -
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Formats a mWh value for a table cell -->
  <xsl:template name="mWhCell">
    <xsl:param name="value"/>
    <xsl:variable name="number" select="number($value)" />
    <xsl:choose>
      <!-- Test for not NaN, not 0, and not Infinity -->
      <xsl:when test="$number != 0 and $number = $number and $number != (1 div 0) and $number != (-1 div 0)">
        <td class="mw">
          <xsl:value-of select="js:numberToLocaleString($number)"/> mWh
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td class="nullValue">-</td>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Formats a % value -->
  <xsl:template name="percent">
    <xsl:param name="value"/>
    <xsl:choose>
      <xsl:when test="$value &gt; 0 and $value &lt; (1 div 0)">
        <xsl:value-of select="$value"/> %
      </xsl:when>
      <xsl:otherwise>-</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Formats a % value for a table cell -->
  <xsl:template name="percentCell">
    <xsl:param name="value" />
    <xsl:choose>
      <xsl:when test="$value &gt; 0 and $value &lt; (1 div 0)">
        <td class="percent">
          <xsl:value-of select="$value"/> %
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td class="nullValue">-</td>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


  <ms:script implements-prefix="js">
    <![CDATA[
    // Formats a number using the current locale (to handle the 1000's separator).
    // The result is rounded so no decimal point is shown.
    function numberToLocaleString(value) {
      // Work out the decimal separator
      var _sep = /\./.test((1.1).toLocaleString())? '.' : ',';
      // Regular expression to trim decimal places
      var re = new RegExp( '\\' + _sep + '\\d+$');
      return Math.round(value).toLocaleString().replace(re,'');
    }

    function padLeft(number, length) {
      var str = '' + number;
      while (str.length < length) {
        str = '0' + str;
      }
      return str;
    }

    // Returns the number of milliseconds between 2 date-times represented as strings.
    function msBetween(startTime, endTime) {
      return startTime > endTime
          ? msBetween(endTime, startTime)
          : parseDateTime(endTime) - parseDateTime(startTime);
    }


    var dateFormat = /(\d{4})-(\d{2})-(\d{2})[T](\d{2}):(\d{2}):(\d{2})/

    // Parses a date-time string and returns a Date (i.e. number of milliseconds)
    function parseDateTime(value) {
      if (!value) {
        return 0;
      }
      var match = dateFormat.exec(value)
      if (!match) {
        return 0;
      }
      return Date.parse(match[1] + '/' + match[2] + '/' + match[3] + ' ' + match[4] + ':' + match[5] + ':' + match[6])
    }

    // Parses just the date portion of a date-time string and returns a Date (i.e. number of milliseconds)
    function parseDate(value) {
      if (!value) {
        return 0;
      }
      var match = dateFormat.exec(value)
      if (!match) {
        return 0;
      }
      return Date.parse(match[1] + '/' + match[2] + '/' + match[3])
    }

    var durationFormat = /P((\d+)D)?T((\d+)H)?((\d+)M)?(\d+)S/

    // Convert a string of the form P10DT1H15M40S to a count of milliseconds
    function parseDurationToMs(value) {
      var match = durationFormat.exec(value)
      if (!match) {
        return 0
      }
      var days = parseInt(match[2] || '0');
      var hrs = parseInt(match[4] || '0');
      var mins = parseInt(match[6] || '0');
      var secs = parseInt(match[7] || '0');
      return ((((((days * 24) + hrs) * 60) + mins) * 60) +  secs) * 1000;
    }

    // Formats a number of milliseconds as h:mm:ss
    function formatDurationMs(value) {
      var ms = parseInt(value);
      var secs = ms / 1000;
      var mins = secs / 60;
      var hrs = Math.floor(mins / 60);
      mins = Math.floor(mins % 60);
      secs = Math.floor(secs % 60);
      return hrs + ':' + padLeft(mins,2) + ':' + padLeft(secs,2);
    }

    // Converts a string representing a date time to a day and month string
    function dateToDayAndMonth(date, dayOffset) {
      var adjustedDate = new Date(parseDate(date) - (dayOffset * 24 * 60 * 60 * 1000));
      return padLeft(adjustedDate.getMonth() + 1, 2) + "-" + adjustedDate.getDate();
    }
    ]]>
  </ms:script>
</xsl:stylesheet>


P<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:eew="http://schemas.microsoft.com/energy/2007" version="1.0">
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <html>
            <head>
                <style>
                    
                    body {
                        font-family: Microsoft Jhenghei UI, Microsoft JhengHei, 新細明體, Verdana, Arial, Helvetica, sans-serif; 
                        font-size: x-small; 
                        margin-right:1.5em}

                    .log-entry {margin-bottom:1em;}

                    
                    .error-log-entry {background-color:#ffcccc; padding:4pt;}

                    
                    .warning-log-entry {background-color:#ffffc6; padding:4pt;}

                    
                    .info-log-entry {background-color:#ffffff; padding:4pt;}

                    
                    .log-entry-header {font-weight:bold;}

                    .log-entry-content {margin: 2pt; }

                    
                    .expander  {
                        display: block; 
                        left: 0em; 
                        width: 1em; 
                        float: left; 
                        color:red; 
                        font-family:'Microsoft Jhenghei UI', 'Microsoft JhengHei', '新細明體', 'Courier New'; 
                        font-weight:bold; 
                        text-decoration:none;
                        padding-top:6pt;}

                    td {
                        font-size:x-small;
                        font-weight: bold;
                    }

                    .log-entry-content table {
;
                    }

                    .log-entry-content td {
                        padding: 3pt;
                    }

                    .detail-name {
                        font-weight:normal;
                    }

                <!-- error log entry --><!-- warning log entry --><!-- info log entry --><!-- log entry header line --><!-- button - contains +/-/nbsp --></style>
            </head>
            <body class="st">
                <xsl:apply-templates/>
            </body>

        </html>
    </xsl:template>

    <!-- Template for the root of the report -->
    <xsl:template match="eew:EnergyReport">
        <h2>電源效率診斷報告</h2>
       <table>
           <tr>
               <td class="detail-name">電腦名稱</td>
               <td>
                   <xsl:value-of select="eew:Troubleshooter[@guid='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[@guid='3d053cee-9926-4ac0-a4e1-63ab80c63af0']/eew:Details/eew:Detail[@guid='300b5d9f-434e-45b0-80d2-4bd55b168ef3']/eew:Value"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">掃描時間</td>
               <td>
                   <xsl:value-of select="eew:ReportInformation/eew:ScanTime"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">掃描期間</td>
               <td>
                   <xsl:value-of select="substring-before(substring-after(eew:ReportInformation/eew:ScanDuration, 'PT'), 'S')"/> 秒
               </td>
           </tr>
           <tr>
               <td class="detail-name">系統製造商</td>
               <td>
                   <xsl:value-of select="eew:Troubleshooter[@guid='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[@guid='3d053cee-9926-4ac0-a4e1-63ab80c63af0']/eew:Details/eew:Detail[@guid='a49d84bf-a8c7-4c26-8f54-eefccac2f084']/eew:Value"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">系統產品名稱</td>
               <td>
                   <xsl:value-of select="eew:Troubleshooter[@guid='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[@guid='3d053cee-9926-4ac0-a4e1-63ab80c63af0']/eew:Details/eew:Detail[@guid='ceddb6e2-626c-4efe-ae58-c7b241693909']/eew:Value"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">BIOS 日期</td>
               <td>
                   <xsl:value-of select="eew:Troubleshooter[@guid='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[@guid='3d053cee-9926-4ac0-a4e1-63ab80c63af0']/eew:Details/eew:Detail[@guid='b586008a-e3ca-457a-8f48-30fe0de3facf']/eew:Value"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">BIOS 版本</td>
               <td>
                   <xsl:value-of select="eew:Troubleshooter[@guid='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[@guid='3d053cee-9926-4ac0-a4e1-63ab80c63af0']/eew:Details/eew:Detail[@guid='c85bfef6-93e7-4f1a-a35d-20655dab095d']/eew:Value"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">作業系統組建</td>
               <td>
                   <xsl:value-of select="eew:Troubleshooter[@guid='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[@guid='3d053cee-9926-4ac0-a4e1-63ab80c63af0']/eew:Details/eew:Detail[@guid='31dc51fd-a872-4546-a54f-ae0da74cdf9f']/eew:Value"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">平台角色</td>
               <td>
                   <xsl:value-of select="eew:Troubleshooter[@guid='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[@guid='3d053cee-9926-4ac0-a4e1-63ab80c63af0']/eew:Details/eew:Detail[@guid='8838163d-e78c-4858-9432-9b034382e9f6']/eew:Value"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">一般電源</td>
               <td>
                   <xsl:value-of select="eew:Troubleshooter[@guid='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[@guid='3d053cee-9926-4ac0-a4e1-63ab80c63af0']/eew:Details/eew:Detail[@guid='9fd5343d-fcb1-42ac-9566-8a8e8409a60b']/eew:Value"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">處理程序計數</td>
               <td>
                   <xsl:value-of select="eew:Troubleshooter[@guid='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[@guid='3d053cee-9926-4ac0-a4e1-63ab80c63af0']/eew:Details/eew:Detail[@guid='d64ab9ff-6978-4c37-ac17-9494347b673b']/eew:Value"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">執行緒計數</td>
               <td>
                   <xsl:value-of select="eew:Troubleshooter[@guid='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[@guid='3d053cee-9926-4ac0-a4e1-63ab80c63af0']/eew:Details/eew:Detail[@guid='375cbf0f-61d5-42b8-a0fd-16c198b7b32f']/eew:Value"/>
               </td>
           </tr>
           <tr>
               <td class="detail-name">報告 GUID</td>
               <td>
                   {<xsl:value-of select="eew:ReportInformation/eew:ReportGuid"/>}
               </td>
           </tr>
       </table>
       <h3>分析結果</h3>
       <xsl:if test="eew:ReportInformation/eew:DroppedEvents &gt; 0 or eew:ReportInformation/eew:DroppedBuffers &gt; 0">
            警告: 已在追蹤期間丟棄事件。這可能會導致分析結果不完整。
       </xsl:if>
       <!-- select all error log entries, then warning, then informational. -->
       <h4>錯誤</h4>
       <xsl:apply-templates select="eew:Troubleshooter[@guid!='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[eew:Severity='Error']"/>
       <h4>警告</h4>
       <xsl:apply-templates select="eew:Troubleshooter[@guid!='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[eew:Severity='Warning']"/>
       <h4>資訊</h4>
       <xsl:apply-templates select="eew:Troubleshooter[@guid!='c78b52e3-9cd7-4802-979c-57ca1283dafa']/eew:AnalysisLog/eew:LogEntry[eew:Severity='Informational']"/>
    </xsl:template>

    <!-- Template for individual analysis log table entries. --> 
    <xsl:template name="GenericLogEntry" match="eew:LogEntry">
        <div class="log-entry">
            <div>
                <xsl:attribute name="class">
                    <xsl:choose>
                        <xsl:when test="eew:Severity='Error'">
                            error-log-entry
                        </xsl:when>
                        <xsl:when test="eew:Severity='Warning'">
                            warning-log-entry
                        </xsl:when>
                        <xsl:otherwise>
                            info-log-entry
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <div class="log-entry-header">
                    <xsl:value-of select="../../eew:Name"/>:<xsl:value-of select="eew:Name"/>
                </div>
                <div class="log-entry-content">
                    <div class="log-entry-description">
                        <xsl:value-of select="eew:Description"/>
                    </div>
                    <xsl:apply-templates/>
                    <span></span>
                </div>
            </div>
        </div>
    </xsl:template>

    <!-- Template for special-cased log entries -->

    <!-- Timer Resolution Stack -->
    <xsl:template match="eew:LogEntry[@guid='f84b604c-98bb-47ba-a789-75cde4996a87']">
        <!-- Apply the generic template if an outstanding timer request exists with the same PID. Otherwise, show nothing. -->
        <xsl:variable name="TimerStackProcessId" select="eew:Details/eew:Detail[@guid='01ee080e-57de-431b-8016-8354fb450f1b']/eew:Value"/>
        <xsl:if test="parent::*/eew:LogEntry[@guid='436954b1-cc2d-4740-9f97-23d1f2c1210e']/eew:Details/eew:Detail[@guid='0ce5eb38-d897-4749-8210-242e77718472'][eew:Value = $TimerStackProcessId]">
            <xsl:call-template name="GenericLogEntry"/>
        </xsl:if>
    </xsl:template>

    <!-- Template for generic analysis log table details. --> 
    
    <!-- Template for analysis log detail list. --> 
    <xsl:template match="eew:Details">
        <table>
            <xsl:apply-templates/>
        </table>
    </xsl:template>

    <!-- Template for generic analysis log table details. --> 
    <xsl:template match="eew:Detail">
        <tr>
            <td>
                <span class="detail-name">
                    <xsl:value-of select="eew:Name"/>
                </span>
            </td>
            <td> 
                <xsl:value-of select="eew:Value"/>
            </td>
        </tr>
    </xsl:template>

    <!-- Template for special-cased analysis log details -->

    <!-- Power Plan Personality.Personality -->
    <xsl:template match="eew:Detail[(@guid='fc84c527-7c74-42c0-a8c5-cc6e1a60b961') or (@guid='b7f44371-d8a6-423d-8417-f2a9a1028f7f')]">
        <tr>
            <td>
                <span class="detail-name">
                    <xsl:value-of select="eew:Name"/>
                </span>
            </td>
            <td> 
                <xsl:choose>
                    <xsl:when test="eew:Value=0">
                        省電
                    </xsl:when>
                    <xsl:when test="eew:Value=1">
                        高效能
                    </xsl:when>
                    <xsl:when test="eew:Value=2">
                        平衡
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="eew:Value"/>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
        </tr>
    </xsl:template>

    <!-- Active Power Plan.Plan GUID -->
    <xsl:template match="eew:Detail[@guid='abf6ffeb-c575-4031-87b6-0ef12a886fee']">
        <tr>
            <td>
                <span class="detail-name">
                    計劃名稱
                </span>
            </td>
            <td>
                <xsl:choose>
                    <xsl:when test="eew:Value='{a1841308-3541-4fab-bc81-f71556f20b4a}'">
                        OEM 省電
                    </xsl:when>
                    <xsl:when test="eew:Value='{8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c}'">
                        OEM 高效能
                    </xsl:when>
                    <xsl:when test="eew:Value='{381b4222-f694-41f0-9685-ff5bb260df2e}'">
                        OEM 平衡
                    </xsl:when>
                    <xsl:otherwise>
                        自訂
                    </xsl:otherwise>
                </xsl:choose>
            </td>
        </tr>
        <tr>
            <td>
                <span class="detail-name">
                    <xsl:value-of select="eew:Name"/>
                </span>
            </td>
            <td> 
                <xsl:value-of select="eew:Value"/>
            </td>
        </tr>
    </xsl:template>

    <!-- Video Quality.Setting -->
    <xsl:template match="eew:Detail[(@guid='23438ed2-d803-4d94-8f66-cfbf094797e7') or (@guid='dc3d55c6-2f0c-4397-bdc4-d2d9a3148969')]">
        <tr>
            <td>
                <span class="detail-name">
                    <xsl:value-of select="eew:Name"/>
                </span>
            </td>
            <td> 
                <xsl:choose>
                    <xsl:when test="eew:Value=0">
                        最佳化視訊品質
                    </xsl:when>
                    <xsl:when test="eew:Value=1">
                        在視訊品質與省電之間取得平衡
                    </xsl:when>
                    <xsl:when test="eew:Value=2">
                        最佳化省電
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="eew:Value"/>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
        </tr>
    </xsl:template>


    <!-- Battery Information.Manufacture Date -->
    <xsl:template match="eew:Detail[@guid='1b9d5465-63f4-4c5d-8259-93effc455084']">
        <xsl:if test="eew:Value!=''">
            <tr>
                <td>
                    <span class="detail-name">
                        <xsl:value-of select="eew:Name"/>
                    </span>
                </td>
                <td> 
                    <xsl:value-of select="eew:Value"/>
                </td>
            </tr>
        </xsl:if>
    </xsl:template>

    <!-- Battery Information.Cycle Count -->
    <xsl:template match="eew:Detail[@guid='17d29a01-f010-4f66-bf60-c121e35cfc2b']">
        <xsl:if test="eew:Value!=''">
            <tr>
                <td>
                    <span class="detail-name">
                        <xsl:value-of select="eew:Name"/>
                    </span>
                </td>
                <td> 
                    <xsl:value-of select="eew:Value"/>
                </td>
            </tr>
        </xsl:if>
    </xsl:template>

    <!-- CPU Utilization.Module -->
    <xsl:template match="eew:Detail[@guid='75067548-7814-4e65-9533-13239cd92ecd']">
        <tr>
            <td> 
                <xsl:value-of select="eew:Value"/>
            </td>
            <td> 
                <xsl:value-of select="following-sibling::node()/eew:Value"/>
            </td>
        </tr>
    </xsl:template>

    <!-- CPU Utilization.Average Module Utilization -->
    <xsl:template match="eew:Detail[@guid='acd9c46d-e149-489a-876d-e1707ed15134']">
    </xsl:template>

    <!-- CPU Utilization.Average Utilization -->
    <xsl:template match="eew:Detail[@guid='9c0f7e30-e8b5-43dd-8c3e-c45bf3101fba']">
        <tr>
            <td>
                <span class="detail-name">
                    <xsl:value-of select="eew:Name"/>
                </span>
            </td>
            <td> 
                <xsl:value-of select="eew:Value"/>
            </td>
        </tr>
        <tr>
            <td>
                <span class="detail-name">
                    模組
                </span>
            </td>
            <td> 
                <span class="detail-name">
                    平均模組使用率 (%)
                </span>
            </td>
        </tr>
    </xsl:template>

    <!-- Timer Stack.Module -->
    <xsl:template match="eew:Detail[@guid='c3b5315f-40d8-47a4-ab56-70a237a8f78f']">
        <tr>
            <td>
                <span class="detail-name">
                    <xsl:if test="preceding-sibling::eew:Detail[1]/attribute::guid!='c3b5315f-40d8-47a4-ab56-70a237a8f78f'">
                        呼叫模組堆疊
                    </xsl:if>
                </span>
            </td>
            <td> 
                <xsl:if test="eew:Value=''">
                    不明模組
                </xsl:if>
                <xsl:value-of select="eew:Value"/>
            </td>
        </tr>
    </xsl:template>

    <!-- Platform Power Management Capabilities.Sx Disabled -->
    <xsl:template match="eew:Detail[(../../@guid='b1e58678-204e-4bd8-b902-09226248d3c7') or (../../@guid='5b2de68c-b12f-47f7-b0f2-394e731a7d02') or (../../@guid='87e0a483-b2fa-436e-b33b-1a00429fe90d') or (../../@guid='26d291ba-d3c9-4371-8fed-99dcb1429273')]">
        <xsl:if test="eew:Value='true'">
            <tr>
                <td>
                    <span>
                        <xsl:value-of select="eew:Name"/>
                    </span>
                </td>
                <td> 
                </td>
            </tr>
        </xsl:if>
    </xsl:template>



    <!-- Template to suppress ouputing raw node content. --> 
    <xsl:template match="*" priority="-9">
    </xsl:template>

</xsl:stylesheet>
PAD<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ms="urn:schemas-microsoft-com:xslt"
    xmlns:ssd="http://schemas.microsoft.com/systemsleepdiagnostics/2016"
    xmlns:js="http://microsoft.com/kernel"
    version="1.0">

    <xsl:output
        method="html"
        omit-xml-declaration="yes"
        indent="no"
        encoding="utf-16" />

    <xsl:variable name="reportInfo" select="/ssd:SystemSleepDiagnostics/ssd:ReportInformation" />
    <xsl:variable name="reportTime" select="string($reportInfo/ssd:ScanTime)" />
    <xsl:variable name="localReportTime" select="string($reportInfo/ssd:LocalScanTime)" />
    <xsl:variable name="reportDuration" select="$reportInfo/ssd:ReportDuration" />
    <xsl:variable name="graphStart" select="$reportInfo/ssd:LocalReportStartTime" />

    <!-- Creates the name of the state -->
    <xsl:template name="toSleepStartReason">
        <xsl:param name="reason" />
        <xsl:choose>
            <xsl:when test="$reason = 0">
                Button or Lid
            </xsl:when>
            <xsl:when test="$reason = 1">
                Thermal Zone
            </xsl:when>
            <xsl:when test="$reason = 2">
                Battery
            </xsl:when>
            <xsl:when test="$reason = 4">
                Application API
            </xsl:when>
            <xsl:when test="$reason = 5">
                Kernel API
            </xsl:when>
            <xsl:when test="$reason = 6">
                Hibernate from Sleep - Fixed Timeout
            </xsl:when>
            <xsl:when test="$reason = 7">
                System Idle
            </xsl:when>
            <xsl:when test="$reason = 10">
                Battery
            </xsl:when>
            <xsl:when test="$reason = 11">
                Hibernate from Sleep - User Away Predicted
            </xsl:when>
            <xsl:when test="$reason = 12">
                Hibernate from Sleep without Wake - User Away Predicted
            </xsl:when>
            <xsl:otherwise>
                Unknown reason
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <!-- Styles -->
    <xsl:template name="css">
        <style type="text/css">
            body {
            font-family: Segoe UI Light;
            letter-spacing: 0.02em;
            background-color: #ffffff;
            color: #000000;
            margin: 0em 5.5em 0em 5.5em;
            }

            h1 {
            color: #00b0f0;
            font-size: 42pt;
            }

            h2 {
            font-size: 15pt;
            color: #00b0f0;
            margin-top: 2em;
            margin-bottom: 0em;
            letter-spacing: 0.08em;
            }

            h3, h4, h5 {
            margin-top: 1em;
            margin-bottom: 0em;
            letter-spacing: 0.08em;
            }

            td {
            padding-left: 0.3em;
            padding-right: 0.3em;
            }

            .nobatts {
            margin-top: 1.5em;
            font-family: Segoe UI Semibold;
            background: #f0f0f0;
            color: #a0a0a0;
            font-size: 13pt;
            padding-left:0.4em;
            padding-right:0.4em;
            padding-top:0.3em;
            padding-bottom:0.3em;
            }

            .explanation {
            color: #777777;
            font-size: 12pt;
            margin-bottom: 1em;
            }

            .explanation2 {
            color: #777777;
            font-size: 12pt;
            margin-bottom: 0.1em;
            }

            table {
            border-width: 0;
            table-layout: fixed;
            font-family: Segoe UI Light;
            letter-spacing: 0.02em;
            color: #000000;
            margin-bottom: 10px;
            }

            table.defs { background-color: transparent; }

            caption {
            padding: 5px 0px 5px 0px;
            font-weight: bold;
            }

            thead {
            font-family: Segoe UI Semibold;
            font-size: 85%;
            }

            text {
            font-size: 12pt;
            font-family: Segoe UI Light;
            fill: #00b0f0;
            }

            .centered { text-align: center; }

            .label {
            font-family: Segoe UI Semibold;
            font-size: 85%;
            color: #acacac;
            }

            #legend {
            background-color: #fafafa;
            margin-bottom: 2.2em;
            border-spacing: 0;
            }

            #legend thead { background-color: #dfdfdf; }
            #legend td, #legend th {
            padding: 4px 5px 4px 5px;
            }

            #legend .spanner {
            text-align: center;
            background-color: #dfdfdf;
            font-size: 85%;
            font-weight: bold;
            padding: 3px;
            }

            #legend td.percent { text-align: left; }

            .graphline-none, .graphline-dotted, .graphline-solid, .graphline-neutral,
            .graphline-low, .graphline-moderate, .graphline-high {
            font-weight: bold;
            }

            .graphline-none { color: #7d7d7d; }
            .graphline-dotted { color: #7d7d7d; }
            .graphline-solid { color: #7d7d7d; }
            .graphline-neutral { color: #7d7d7d; }
            .graphline-low { color: #2a7a2a; }
            .graphline-moderate { color: #cc7e06; }
            .graphline-high { color: #970d00; }

            .top-blocker td, #summary-table td {
            padding: 0;
            }

            .top-blocker td a, #summary-table td a {
            padding: 0 0.3em 0 0.3em;
            display: block;
            height: 100%;
            }

            .top-blocker a:link, .top-blocker a:active, .top-blocker a:visited,
            #summary-table a:link, #summary-table a:active, #summary-table a:visited {
            text-decoration: none;
            color: #000000;
            }

            #summary-table th,
            .session-summary th,
            .top-blocker th,
            .pdc-phases th,
            .device-components th {
            background-color: transparent;
            }

            #summary-table tbody tr,
            .session-summary tbody tr,
            .top-blocker tbody tr,
            .device-components tbody tr,
            .pdc-phases tbody tr {
            background-color: #e0e0e0;
            }

            #summary-table .row-neutral,
            .session-summary .row-neutral,
            .top-blocker .row-neutral,
            .device-components .row-neutral,
            .pdc-phases .row-neutral {
            background-color: #e0e0e0;
            }

            #summary-table .row-low,
            .session-summary .row-low,
            .top-blocker .row-low,
            .device-components .row-low,
            .pdc-phases .row-low {
            background-color: #ace3ac;
            }

            #summary-table .row-moderate,
            .session-summary .row-moderate,
            .top-blocker .row-moderate,
            .device-components .row-moderate,
            .pdc-phases .row-moderate {
            background-color: #fcd69a;
            }

            #summary-table .row-high,
            .session-summary .row-high,
            .top-blocker .row-high,
            .device-components .row-high,
            .pdc-phases .row-high {
            background-color: #ffb2aa;
            }

            #summary-table .row-info,
            .session-summary .row-info,
            .top-blocker .row-info,
            .device-components .row-info,
            .pdc-phases .row-info {
            background-color: #86becb;
            }

            #summary-table tbody tr:hover,
            .top-blocker tbody tr:hover {
            background-color: #f0f0f0;
            }

            #summary-table .row-neutral:hover,
            .top-blocker .row-neutral:hover {
            background-color: #f0f0f0;
            }

            #summary-table .row-low:hover,
            .top-blocker .row-low:hover {
            background-color: #caedca;
            }

            #summary-table .row-moderate:hover,
            .top-blocker .row-moderate:hover {
            background-color: #fde5c0;
            }

            #summary-table .row-high:hover,
            .top-blocker .row-high:hover {
            background-color: #ffd5d1;
            }

            td.colBreak { padding: 0; width: 0.15em; }

            td.state { text-align: center; }
            td.chargeOrDrain { text-align: center; }
            td.percentLowPowerStateTime { text-align: center; }
            td.percent { font-family: Segoe UI Symbol; text-align: center; }
            td.hms { font-family: Segoe UI Symbol; text-align: center; }
            td.dateTime { font-family: Segoe UI Symbol; }
            td.blank { background-color: #ffffff; }
            td.nullValue { text-align: center; }
            td.center { text-align: center; }

            col.percent { width: 7.5em; }

            td.mw {
            font-family: Segoe UI Symbol;
            text-align: center;
            }

            td.acdc { text-align: center; }

            span.date {
            display: inline-block;
            width: 5.5em;
            }

            span.time {
            text-align: right;
            width: 4.2em;
            display: inline-block;
            }

            text { font-family: Segoe UI Symbol; }

            .noncontigbreak {
            height: 0.3em;
            background-color: #1A1A28;
            }

            div.analysis-container {
            margin-bottom: 10px;
            border: 1px solid #ffffff;
            }

            div.analysis-container h1 {
            padding: 10px;
            font-size: 14px;
            margin: 0px;
            cursor: pointer;
            }

            div.analysis-body, div.analysis-body-collapsed {
            padding: 10px;
            }

            div.analysis-body { display: block; }
            div.analysis-body-collapsed { display: none; }

            .analysis-base { background-color: #f7f7f7; }
            .analysis-base h1 { color: #a0a0a0; background-color: #d0d0d0; }
            .analysis-base h1:hover { background-color: #dfdfdf; }

            .analysis-neutral { background-color: #f0f0f0; }
            .analysis-neutral h1 { color: #a0a0a0; background-color: #d0d0d0; }
            .analysis-neutral h1:hover { background-color: #dfdfdf; }

            .analysis-high { background-color: #ffd5d1; }
            .analysis-high h1 { background-color: #ff8e83; color: #970d00; }
            .analysis-high h1:hover { background-color: #ffb2aa; }

            .analysis-moderate { background-color: #fde5c0; }
            .analysis-moderate h1 { background-color: #fbc674; color: #cc7e06; }
            .analysis-moderate h1:hover { background-color: #fcd69a; }

            .analysis-low { background-color: #caedca; }
            .analysis-low h1 { background-color: #8fd98f; color: #2a7a2a; }
            .analysis-low h1:hover { background-color: #ace3ac; }

            .analysis-info { background-color: #b2e5e5; }
            .analysis-info h1 { background-color: #1aa3a3; color: #0b5e56; }
            .analysis-info h1:hover { background-color: #86becb; }

            .analysis-empty {
            color: #a0a0a0;
            font-size: 14px;
            padding: 10px;
            font-weight: bold;
            }
        </style>
        <!-- split the css into two style tags to get around the locstudio 8192 character limit -->
        <style>
            .expander { font-family: "Consolas"; font-weight: bold; }
            .warning { background-color: #fde5c0; }
            .warning h1 { background-color: #fbc674; color: #cc7e06; }
            .warning h1:hover { background-color: #fcd69a; }
            .error { background-color: #ffd5d1; }
            .error h1 { background-color: #ff8e83; color: #970d00; }
            .error h1:hover { background-color: #ffb2aa; }
            code { font-family: "Consolas"; }

            pre {
            font-family: "Consolas";
            display: block;
            border: 1px dashed #b0b0b0;
            padding: 10px;
            margin: 10px 0px 10px 0px;
            }

            .scroll-top-button {
            border: 2px solid #000000;
            background-color: #ffffff;
            padding: 5px 3px 5px 3px;
            font-size: 12px;
            font-family: Segoe UI Semibold;
            float: left;
            border-radius: 18px;
            margin-top: 15px;
            margin-left: -60px;
            }

            .scroll-top-button:hover {
            background-color: #f0f0f0;
            cursor: pointer;
            }

            .scenario-details, .scenario-details-collapsed {
            padding: 5px;
            background-color: #f0f0f0;
            width: 864px;
            border-left: 2px solid #ffffff;
            }

            .scenario-details { display: block; }
            .scenario-details-collapsed { display: none; }

            .details-expander {
            background-color: #dfdfdf;
            font-weight: bold;
            cursor: pointer;
            }

            .details-expander:hover { background-color: #cfcfcf; }

            ul { list-style: square; }
        </style>
    </xsl:template>

    <!-- JavaScript for the page -->
    <xsl:template name="jsUtil">
    <xsl:text disable-output-escaping="yes">
    // Add support for drawing dashed lines to Canvas
    CanvasRenderingContext2D.prototype.dashedLine = function (x0, y0, x1, y1, dashArray) {
        if (dashArray == null) {
            dashArray = [4, 4];
        }

        var dx = x1 - x0;
        var dy = y1 - y0;
        var distance = Math.sqrt(Math.pow((x1 - x0), 2) + Math.pow((y1 - y0), 2));
        var theta = Math.atan(dy / dx);
        if (dx &lt; 0) {
            theta += Math.PI;
        }

        var i = 0;
        while (distance &gt; 0) {
            var length = Math.min(distance, dashArray[i]);
            x0 += length * Math.cos(theta);
            y0 += length * Math.sin(theta);
            if (i % 2 == 0) {
                this.lineTo(x0, y0);

            } else {
                this.moveTo(x0, y0);
            }

            distance -= length;
            i = (i + 1) % dashArray.length;
        }
    };
    </xsl:text>
    </xsl:template>

    <xsl:template name="jsDateUtil">
    <xsl:text disable-output-escaping="yes">
    // Formats a number using the current locale (to handle the 1000's separator).
    // The result is rounded so no decimal point is shown.
    function numberToLocaleString(value) {
        var localeString = Math.round(parseFloat(value + '')).toLocaleString();
        return localeString.substring(0, localeString.indexOf('.'));
    }

    function padLeft(number, length) {
        var str = '' + number;
        while (str.length &lt; length) {
            str = '0' + str;
        }

        return str;
    }

    // Returns the number of milliseconds between 2 date-times represented as strings.
    function msBetween(startTime, endTime) {
        return startTime &gt; endTime
               ? msBetween(endTime, startTime)
               : parseDateTime(endTime) - parseDateTime(startTime);
    }

    var dateFormat = /(\d{4})-(\d{2})-(\d{2})[T](\d{2}):(\d{2}):(\d{2})/

    // Parses a date-time string and returns a Date (i.e. number of milliseconds)
    function parseDateTime(value) {
        if (!value) {
            return 0;
        }

        var match = dateFormat.exec(value)
        if (!match) {
            return 0;
        }

        return Date.parse(match[1] + '/' + match[2] + '/' +
                          match[3] + ' ' + match[4] + ':' +
                          match[5] + ':' + match[6])
    }

    // Parses just the date portion of a date-time string and returns a Date
    // (i.e. number of milliseconds)
    function parseDate(value) {
        if (!value) {
            return 0;
        }

        var match = dateFormat.exec(value)
        if (!match) {
            return 0;
        }

        return Date.parse(match[1] + '/' + match[2] + '/' + match[3])
    }

    var durationFormat = /P((\d+)D)?T((\d+)H)?((\d+)M)?(\d+)S/

    // Convert a string of the form P10DT1H15M40S to a count of milliseconds
    function parseDurationToMs(value) {
        var match = durationFormat.exec(value)
        if (!match) {
            return 0
        }

        var days = parseInt(match[2] || '0');
        var hrs = parseInt(match[4] || '0');
        var mins = parseInt(match[6] || '0');
        var secs = parseInt(match[7] || '0');
        return ((((((days * 24) + hrs) * 60) + mins) * 60) +  secs) * 1000;
    }

    // Converts milliseconds to days
    function msToDays(ms) {
        return (ms / 1000 / 60 / 60 / 24);
    }

    function daysToMs(days) {
        return (days * 24 * 60 * 60 * 1000);
    }

    // Formats a number of milliseconds as h:mm:ss
    function formatDurationMs(value) {
        var ms = parseInt(value);
        var secs = ms / 1000;
        var mins = secs / 60;
        var hrs = Math.floor(mins / 60);
        mins = Math.floor(mins % 60);
        secs = Math.floor(secs % 60);
        return hrs + ':' + padLeft(mins,2) + ':' + padLeft(secs,2);
    }

    // Converts a millisecond timestamp to a day and month string
    // Note: dayOffset is forward from date.
    function dateToDayAndMonth(ms, dayOffset) {
        var adjustedDate = new Date(ms + (dayOffset * 24 * 60 * 60 * 1000));
        return padLeft(adjustedDate.getMonth() + 1, 2) + "-" +
               padLeft(adjustedDate.getDate(), 2);
    }

    // Takes a millisecond timestamp and returns a new millisecond timestamp
    // rounded down to the current day.
    function dateFloor(ms) {
        var dt = new Date(ms);
        return Date.parse(dt.getFullYear() + '/' + (dt.getMonth() + 1) + '/' + dt.getDate());
    }
    </xsl:text>
    </xsl:template>

    <xsl:template name="jsTimegraph">
    <xsl:text disable-output-escaping="yes">
    Timegraph = {
        axisTop: 9.5,
        axisRight: 24.5,
        axisBottom: 25.5,
        axisLeft: 25.5,
        ticks: 10,

        // Maximum number of 24 hour ticks for showing 12 and 6 hour ticks

        ticks12Hour: 360,
        ticks6Hour: 180,

        // Shading

        shadingColor: "#d0d0d0",

        precompute: function (graph) {
            var canvas = graph.canvas;
            var data = graph.data;
            var min = 0;
            var max = 0;

            graph.height = canvas.height - Timegraph.axisTop - Timegraph.axisBottom;
            graph.width = canvas.width - Timegraph.axisLeft - Timegraph.axisRight;
            for (var i = 0; i &lt; data.length; i++) {
                data[i].t0 = parseDateTime(data[i].x0);
                data[i].t1 = parseDateTime(data[i].x1);

                if (i == 0) {
                    min = data[i].t0;
                    max = data[i].t1;
                }

                if (data[i].t0 &lt; min) {
                    min = data[i].t0;
                }

                if (data[i].t1 &gt; max) {
                    max = data[i].t1;
                }

                data[i].yy0 =
                    Timegraph.axisTop + graph.height - data[i].y0 * graph.height;

                data[i].yy1 =
                    Timegraph.axisTop + graph.height - data[i].y1 * graph.height;
            }

            if (graph.startTime != null) {
                graph.startMs = parseDateTime(graph.startTime);

            } else {
                graph.startMs = min;
            }

            graph.endMs = max;
            graph.durationMs = max - min;
        },

        drawFrame: function (graph) {
            var canvas = graph.canvas;
            var context = graph.context;

            graph.width =
                canvas.width - Timegraph.axisRight - Timegraph.axisLeft;

            graph.height =
                canvas.height - Timegraph.axisTop - Timegraph.axisBottom;

            context.beginPath();
            context.moveTo(Timegraph.axisLeft, Timegraph.axisTop);
            context.lineTo(Timegraph.axisLeft + graph.width,
                           Timegraph.axisTop);

            context.lineTo(Timegraph.axisLeft + graph.width,
                           Timegraph.axisTop + graph.height);

            context.lineTo(Timegraph.axisLeft,
                           Timegraph.axisTop + graph.height);

            context.lineTo(Timegraph.axisLeft, Timegraph.axisTop);
            context.strokeStyle = "#c0c0c0";
            context.stroke();
        },

        drawRange: function (graph) {
            var canvas = graph.canvas;
            var context = graph.context;

            context.font = "12pt Segoe UI";
            context.fillStyle = "#00b0f0";
            context.fillText("%", 0, Timegraph.axisTop + 5, Timegraph.axisLeft);

            var tickSpacing = graph.height / 10;
            var offset = Timegraph.axisTop + tickSpacing;
            var tickValue = 90;
            for (var i = 0; i &lt; 9; i++) {
                context.beginPath();
                context.moveTo(Timegraph.axisLeft, offset);
                context.lineTo(Timegraph.axisLeft + graph.width,
                               offset);

                context.stroke();
                context.fillText(tickValue.toString(),
                                 0,
                                 offset + 5,
                                 Timegraph.axisLeft);

                offset += tickSpacing;
                tickValue -= 10;
            }
        },

        drawDomain: function (graph, start, end) {
            var canvas = graph.canvas;
            var context = graph.context;
            var data = graph.data;
            var duration = end - start;
            if ((end &lt; start)) {
                return;
            }

            var startDay = dateFloor(start);
            var t0 = startDay;
            var t1 = dateFloor(end);
            var dayOffset = 0;
            if (start &gt; t0) {
                t0 = t0 + daysToMs(1);
                dayOffset++;
            }

            if (t0 &gt;= t1) {
                return;
            }

            var increment =
                Math.max(Math.floor((t1 - t0) / daysToMs(Timegraph.ticks)), 1);

            var incrementMs = daysToMs(increment);
            var spacing = (incrementMs / duration) * graph.width;
            var offset = (t0 - start) / duration;
            var ticksCount = Math.floor((t1 - t0) / incrementMs);
            for (offset = offset * graph.width + Timegraph.axisLeft;
                 offset &lt; (graph.width + Timegraph.axisLeft);
                 offset += spacing) {

                context.beginPath();
                context.moveTo(offset, Timegraph.axisTop);
                context.lineTo(offset, Timegraph.axisTop + graph.height);
                context.stroke();
                context.fillText(dateToDayAndMonth(startDay, dayOffset),
                                 offset,
                                 Timegraph.axisTop + graph.height + 15,
                                 spacing);

                dayOffset += increment;
            }
        },

        plot: function (graph, start, end) {
            var canvas = graph.canvas;
            var context = graph.context
            var data = graph.data;

            if ((end &lt; start)) {
                return;
            }

            var duration = end - start;
            Timegraph.drawDomain(graph, start, end);
            context.fillStyle = Timegraph.shadingColor;
            for (var i = 0; i &lt; data.length - 1; i++) {
                if ((data[i].t0 &lt; start) || (data[i].t0 &gt; end) ||
                    (data[i].t1 &gt; end)) {

                    continue;
                }

                var x1 = (data[i].t0 - start) / duration;
                x1 = x1 * graph.width + Timegraph.axisLeft;

                var x2 = (data[i].t1 - start) / duration;
                x2 = x2 * graph.width + Timegraph.axisLeft;

                context.globalAlpha = 0.3;
                context.fillRect(x1, Timegraph.axisTop, (x2 - x1), graph.height);
                context.globalAlpha = 1;
                context.beginPath();
                context.strokeStyle = graph.lineTypes[data[i].type].color;
                context.lineWidth = 1.5;
                if (graph.lineTypes[data[i].type].dotted == 1) {
                    context.dashedLine(x1, data[i].yy0, x2, data[i].yy1);

                } else {
                    context.moveTo(x1, data[i].yy0);
                    context.lineTo(x2, data[i].yy1);
                }

                context.stroke();
            }
        },

        draw: function (graph) {
            var canvas = document.getElementById(graph.element);
            if (canvas == null) {
                return;
            }

            var context = canvas.getContext('2d');
            if (context == null) {
                return;
            }

            graph.width = 0;
            graph.height = 0;
            graph.context = context;
            graph.canvas = canvas;

            Timegraph.precompute(graph);
            Timegraph.drawFrame(graph);
            Timegraph.drawRange(graph);
            Timegraph.plot(graph, graph.startMs, graph.endMs);
        }
    };
    </xsl:text>
    </xsl:template>

    <xsl:template name="jsCollapser">
    <xsl:text disable-output-escaping="yes">
    Collapser = {
        topActiveBlockerDivs: {},
        detailsContainers: {},

        getContainerBody: function (container) {
            var children = container.childNodes;
            var containerBody = null;
            for (var i = 0; i &lt; children.length; i++) {
                if (children[i].tagName == "DIV" &amp;&amp;
                    (children[i].className == "analysis-body-collapsed" ||
                     children[i].className == "analysis-body")) {

                    containerBody = children[i];
                    break;
                }
            }

            return containerBody;
        },

        togglePanel: function (container) {
            var containerBody = Collapser.getContainerBody(container);
            if (containerBody == null) {
                return;
            }

            var heading = container.getElementsByTagName("H1")[0];
            var expander = heading.getElementsByClassName("expander")[0];
            if (containerBody.className == "analysis-body-collapsed") {
                containerBody.className = "analysis-body";
                expander.innerHTML = "- ";

            } else {
                containerBody.className = "analysis-body-collapsed";
                expander.innerHTML = "+ ";
            }
        },

        toggleDetails: function (element) {
            if (element.className == "scenario-details-collapsed") {
                element.className = "scenario-details";

            } else {
                element.className = "scenario-details-collapsed";
            }
        },

        initializePanels: function () {
            var elements = document.getElementsByClassName("analysis-container");
            for (var i = 0; i &lt; elements.length; i++) {
                var element = elements[i];
                var heading = element.getElementsByTagName("h1")[0];
                if (heading == null) {
                    continue;
                }

                heading.onclick = function () {
                    var container = this.parentNode;
                    Collapser.togglePanel(container);
                };
            }
        },

        initializeDetails: function() {
            var elements = document.getElementsByClassName("details-expander");
            for (var i = 0; i &lt; elements.length; i++) {
                var element = elements[i];
                var targetId = "details-" + element.id.replace("details-expand-", "");
                var targetElement = document.getElementById(targetId);
                Collapser.detailsContainers[element.id] = targetElement;
                element.onclick = function () {
                    var targetElement = Collapser.detailsContainers[this.id];
                    Collapser.toggleDetails(targetElement);
                };
            }
        },

        initializeLinks: function () {
            var links = document.getElementsByClassName("top-active-link");
            for (var i = 0; i &lt; links.length; i++) {
                var link = links[i];
                var targetId = link.getAttribute("href").substring(1);
                var targetElement = document.getElementById(targetId);
                if (targetElement.tagName.toLowerCase() == "tr") {
                    // tr, tbody, table, div.analysis-body-*, div.analysis-container
                    Collapser.topActiveBlockerDivs[targetId] =
                        targetElement.parentNode.parentNode.parentNode.parentNode;

                } else {
                    Collapser.topActiveBlockerDivs[targetId] = targetElement;
                }

                link.onclick = function () {
                    var targetId = this.getAttribute("href").substring(1);
                    var targetContainer = Collapser.topActiveBlockerDivs[targetId];
                    var container = targetContainer;
                    while ((container != null) &amp;&amp; (container.tagName == "DIV")) {
                        var containerBody = Collapser.getContainerBody(container);
                        if (containerBody == null) {
                            return;
                        }

                        if (containerBody.className == "analysis-body-collapsed") {
                            Collapser.togglePanel(container);
                        }

                        container = container.parentNode.parentNode;
                    }

                    targetContainer.scrollIntoView(true);
                };
            }
        },

        initializeCollapser: function () {
            Collapser.initializePanels();
            Collapser.initializeDetails();
            TableDecorator.decorate({
                element: ".top-blocker",
                withClass: "top-active-link"
            });

            Collapser.initializeLinks();
        },

        initialize: function () {
            if (window.addEventListener != null) {
                window.addEventListener("load", Collapser.initializeCollapser, false);

            } else if (window.attachEvent != null) {
                window.attachEvent("onload", Collapser.initializeCollapser);
            }
        }
    };
    </xsl:text>
    </xsl:template>

    <xsl:template name="jsTableDecorator">
    <xsl:text disable-output-escaping="yes">
    TableDecorator = {
        decorateTable: function (table, linkClass) {
            if (table == null) {
                return;
            }

            var rows = table.getElementsByTagName("tr");
            for (var i = 0; i &lt; rows.length; i++) {
                var row = rows[i];
                var anchor = row.getElementsByClassName("row-link")[0];
                if (anchor == null || anchor.tagName.toLowerCase() != "a") {
                    continue;
                }

                var link = anchor.getAttribute("href");
                for (var j = 0; j &lt; row.children.length; j++) {
                    var cell = row.children[j];
                    if (cell == anchor.parentNode) {
                        continue;
                    }

                    var classString = "";
                    if (linkClass != null) {
                        classString = " class=\"" + linkClass + "\"";
                    }

                    cell.innerHTML =
                        "&lt;a href=\"" + link + "\"" + classString + "&gt;" +
                        cell.innerHTML + "&lt;/a&gt;";
                }
            }
        },

        decorate: function (tableData) {
            var selection = tableData.element;
            if (selection.charAt(0) == ".") {
                var className = selection.substring(1);
                var elements = document.getElementsByClassName(className);
                for (var i = 0; i &lt; elements.length; i++) {
                    if (elements[i].tagName.toLowerCase() == "table") {
                        TableDecorator.decorateTable(elements[i], tableData.withClass);
                    }
                }

            } else if (selection.charAt(0) == "#") {
                var idName = selection.substring(1);
                var element = document.getElementById(idName);
                if (element.tagName.toLowerCase() == "table") {
                    TableDecorator.decorateTable(element, tableData.withClass);
                }
            }
        },
    };
    </xsl:text>
    </xsl:template>

    <xsl:template name="jsScrollTop">
    <xsl:text disable-output-escaping="yes">
    function initializeScrollTop() {
        var elements = document.getElementsByClassName("scroll-top-button");
        for (var i = 0; i &lt; elements.length; i++) {
            var element = elements[i];
            element.onclick = function () {
                window.scroll(0, 0);
                window.location.replace("#");
                if (typeof window.history.replaceState == "function") {
                    history.replaceState({}, "", window.location.href.slice(0, -1));
                }
            }
        }
    }
    </xsl:text>
    </xsl:template>

    <xsl:template name="javascript">
        <xsl:param name="idleTimes" />

        <script type="text/javascript">
            <xsl:call-template name="jsUtil" />
            <xsl:call-template name="jsDateUtil" />
            <xsl:call-template name="jsTimegraph" />
            <xsl:call-template name="jsScrollTop" />
            <xsl:call-template name="jsCollapser" />
            <xsl:call-template name="jsTableDecorator" />
                Collapser.initialize();

            <xsl:text disable-output-escaping="yes">
                idleTimeGraphLineTypes = [
                    { color: "none", dotted: 0 },
                    { color: "#7d7d7d", dotted: 0 },
                    { color: "#2a7a2a", dotted: 0 },
                    { color: "#cc7e06", dotted: 0 },
                    { color: "#970d00", dotted: 0 },
                    { color: "#7d7d7d", dotted: 1 },
                    { color: "#2a7a2a", dotted: 1 },
                    { color: "#cc7e06", dotted: 1 },
                    { color: "#970d00", dotted: 1 },
                ];
            </xsl:text>

            <xsl:apply-templates select="$idleTimes" mode="jsIdleTime" />

            <xsl:text disable-output-escaping="yes">
                function main() {
            </xsl:text>
            <xsl:text disable-output-escaping="yes">
                    TableDecorator.decorate({element: "#summary-table"});
            </xsl:text>
            <xsl:apply-templates select="$idleTimes" mode="jsMainIdleTime" />
            <xsl:text disable-output-escaping="yes">

                    initializeScrollTop();
                }

                if (window.addEventListener != null) {
                    window.addEventListener("load", main, false);

                } else if (window.attachEvent != null) {
                    window.attachEvent("onload", main);
                }
            </xsl:text>
        </script>
    </xsl:template>


    <xsl:template match="ssd:IdleTime" mode="jsMainIdleTime">
        <xsl:text>
            Timegraph.draw({
                element: "idle-time-graph-</xsl:text>
        <xsl:value-of select="position()" />
        <xsl:text>",
                data: idleTimeGraphData_</xsl:text>
        <xsl:value-of select="position()" />
        <xsl:text>,
                rangeMax: 100,
                lineTypes: idleTimeGraphLineTypes,
                startTime: "</xsl:text>
        <xsl:value-of select="@LocalStartTimestamp" />
        <xsl:text disable-output-escaping="yes">",
                endTime: "</xsl:text>
        <xsl:value-of select="@LocalEndTimestamp" />
        <xsl:text disable-output-escaping="yes">"
            });
            &#xa;
        </xsl:text>
    </xsl:template>

    <xsl:template match="ssd:IdleTime" mode="jsIdleTime">
        <xsl:text>idleTimeGraphData_</xsl:text>
        <xsl:value-of select="position()" />
        <xsl:text> = [&#xa;</xsl:text>
        <xsl:apply-templates select="ssd:Datapoint" mode="jsIdleTime" />
        <xsl:text>
            ];
        </xsl:text>
    </xsl:template>

    <xsl:template match="ssd:Datapoint" mode="jsIdleTime">
        <xsl:text>{ </xsl:text>
        <xsl:text>x0: "</xsl:text>
        <xsl:value-of select="@LocalStartTimestamp" />
        <xsl:text>", </xsl:text>
        <xsl:text>x1: "</xsl:text>
        <xsl:value-of select="@LocalEndTimestamp" />
        <xsl:text>", </xsl:text>
        <xsl:text>y0: </xsl:text>
        <xsl:value-of select="@AccumulatedIdleTime div @MaxAccumulatedTime" />
        <xsl:text>, </xsl:text>
        <xsl:text>y1: </xsl:text>
        <xsl:value-of select="@AccumulatedIdleTime div @MaxAccumulatedTime" />
        <xsl:text>, </xsl:text>
        <xsl:text>type: </xsl:text>
        <xsl:variable name="systemIsIdle">
            <xsl:choose>
                <xsl:when test="@SystemIdle = '1'">2</xsl:when>
                <xsl:otherwise>4</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:value-of select="$systemIsIdle" />
        <xsl:text>}, &#xa;</xsl:text>
    </xsl:template>

    <!-- Formats a date-time for display -->
    <xsl:template name="formatDateTime">
        <xsl:param name="dateTime"/>
        <xsl:param name="showDate" select="true()" />
        <xsl:variable name="date" select="substring-before($dateTime, 'T')"/>
        <xsl:variable name="time" select="translate(substring-after($dateTime, 'T'), 'T ', '')"/>

        <span class="date">
            <xsl:if test="$showDate">
                <xsl:value-of select="$date"/>
            </xsl:if>
            <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
            <xsl:text> </xsl:text>
        </span>
        <span class="time">
            <xsl:value-of select="$time"/>
        </span>
    </xsl:template>

    <xsl:template name="systemInformation">
        <table class="defs">
            <col />
            <tr>
                <td class="label">
                    REPORT TIME
                </td>
                <td>
                    <xsl:variable name="date" select="substring-before($localReportTime, 'T')"/>
                    <xsl:variable name="time" select="translate(substring-after($localReportTime, 'T'), 'T ', '')"/>

                    <span>
                        <xsl:value-of select="$date"/>
                        <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
                        <xsl:text> </xsl:text>
                    </span>
                    <span>
                        <xsl:value-of select="$time"/>
                    </span>
                </td>
            </tr>
        </table>
    </xsl:template>

    <xsl:template match="ssd:UserAbsenceSessions" mode="summaryTable">
        <table id="summary-table">
            <colgroup>
                <col style="width: 2em" />
                <col style="width: 11em;" />
                <col style="width: 5em;" />
                <col style="width: 5em;" />
            </colgroup>
            <thead>
                <tr>
                    <th></th>
                    <th>TIME USER WENT IDLE</th>
                    <th>IDLE DURATION</th>
                    <th>SLEEP STATE ENTERED</th>
                </tr>
            </thead>

            <xsl:choose>
                <xsl:when test="count(ssd:Session)">
                    <xsl:apply-templates select="ssd:Session" mode="summaryTable"  />
                </xsl:when>
                <xsl:otherwise>
                    <!-- No data. Show one line of dashes -->
                    <tr>
                        <td class="nullValue">-</td>
                        <td class="nullValue">-</td>
                        <td class="nullValue">-</td>
                        <td class="nullValue">-</td>
                    </tr>
                </xsl:otherwise>
            </xsl:choose>
        </table>
    </xsl:template>

    <xsl:template match="ssd:Session" mode="summaryTable">
        <tr>
            <xsl:attribute name="class">
                <xsl:text>row-low</xsl:text>
            </xsl:attribute>
            <td class="centered">
                <a>
                    <xsl:attribute name="href">
                        <xsl:text>#user-not-present-session-</xsl:text>
                        <xsl:value-of select="position()" />
                    </xsl:attribute>
                    <xsl:attribute name="class">
                        <xsl:text>row-link</xsl:text>
                    </xsl:attribute>
                    <xsl:value-of select="position()" />
                </a>
            </td>
            <td class="dateTime">
                <xsl:call-template name="formatDateTime">
                    <xsl:with-param name="dateTime" select="@NotPresentLocalTimestamp" />
                    <xsl:with-param name="showDate" select="js:parseDate(string(@NotPresentLocalTimestamp)) != js:parseDate(string(preceding-sibling::*[1]/@NotPresentLocalTimestamp))" />
                </xsl:call-template>
            </td>
            <td class="hms">
                <xsl:value-of select="js:formatDurationMs(string(@NotPresentDuration div 10000))" />
            </td>
            <td class="centered">
                <xsl:value-of select="js:createSleepIntervalString(string(@SleepState))" />
            </td>
        </tr>

    </xsl:template>

    <xsl:template match="ssd:UserAbsenceSessions" mode="analysisResults">
        <xsl:apply-templates select="ssd:Session" mode="analysisResults" />
    </xsl:template>

    <xsl:template match="ssd:Session" mode="analysisResults">
        <a>
            <xsl:attribute name="name">
                <xsl:text>user-not-present-session-</xsl:text>
                <xsl:value-of select="position()" />
            </xsl:attribute>
        </a>
        <div class="scroll-top-button">Top</div>
        <h3>
            User Not Present Session <xsl:value-of select="position()" />
        </h3>
        <table class="session-summary">
            <colgroup>
                <col style="width: 2em" />
                <col style="width: 11em;" />
                <col style="width: 5em;" />
                <col style="width: 5em;" />
            </colgroup>
            <thead>
                <tr>
                    <th></th>
                    <th>TIME USER WENT IDLE</th>
                    <th>IDLE DURATION</th>
                    <th>SLEEP STATE ENTERED</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <xsl:attribute name="class">
                        <xsl:text>row-low</xsl:text>
                    </xsl:attribute>
                    <td class="centered">
                        <xsl:value-of select="position()" />
                    </td>
                    <td class="dateTime">
                        <xsl:call-template name="formatDateTime">
                            <xsl:with-param name="dateTime" select="@NotPresentLocalTimestamp" />
                        </xsl:call-template>
                    </td>
                    <td class="hms">
                        <xsl:value-of select="js:formatDurationMs(string(@NotPresentDuration div 10000))" />
                    </td>
                    <td class="centered">
                        <xsl:value-of select="js:createSleepIntervalString(string(@SleepState))" />
                    </td>
                </tr>
            </tbody>
        </table>

        <xsl:if test="count(ssd:Runtime/ssd:IdleTime)">
            <h4>Idle Time Graph</h4>
            <div class="explanation">Diagnostics of system idle.</div>
            <canvas>
                <xsl:attribute name="id">
                    <xsl:text>idle-time-graph-</xsl:text>
                    <xsl:value-of select="position()" />
                </xsl:attribute>
                <xsl:attribute name="width">
                    <xsl:text>864</xsl:text>
                </xsl:attribute>
                <xsl:attribute name="height">
                    <xsl:text>300</xsl:text>
                </xsl:attribute>
                <xsl:text> </xsl:text>
            </canvas>
        </xsl:if>

        <xsl:apply-templates select="ssd:Runtime/ssd:PowerRequests" mode="analysisTopLevel" />
        <xsl:apply-templates select="ssd:Runtime/ssd:IdleEvents" mode="analysisTopLevel" />
        <xsl:apply-templates select="ssd:SleepIntervals" mode="analysisTopLevel" />
      <xsl:apply-templates select="ssd:SmartUserPresenceInformation" />
    </xsl:template>

    <xsl:template match="ssd:PowerRequests" mode="analysisTopLevel">
        <div>
            <xsl:attribute name="class">
                <xsl:text>analysis-container </xsl:text>
                <xsl:text>analysis-</xsl:text>
                <xsl:value-of select="@ActivityLevel" />
            </xsl:attribute>
            <h1>
                <span class="expander">+ </span>Power Requests
            </h1>
            <div class="analysis-body-collapsed">
                <xsl:choose>
                    <xsl:when test="count(ssd:PowerRequest)">
                        <xsl:apply-templates select="ssd:PowerRequest" />
                    </xsl:when>
                    <xsl:otherwise>
                        <div class="analysis-empty">No power requests present during this session.</div>
                    </xsl:otherwise>
                </xsl:choose>
            </div>
        </div>
    </xsl:template>

    <xsl:template match="ssd:PowerRequest">
        <div>
            <xsl:attribute name="class">
                <xsl:text>analysis-container </xsl:text>
                <xsl:text>analysis-</xsl:text>
                <xsl:value-of select="@ActivityLevel" />
            </xsl:attribute>
            <h1>
                <span class="expander">+ </span>
                <xsl:value-of select="@Caller" />
            </h1>
            <div class="analysis-body-collapsed">
                <table class="defs">
                    <tr>
                        <td class="label">START TIME</td>
                        <td class="label">DURATION</td>
                        <td class="label">TYPE</td>
                        <td class="label">TOKEN</td>
                    </tr>
                    <tr>
                        <td class="percent">
                            <xsl:value-of select="@LocalStartTime" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="js:formatDurationMs(string(@Duration div 10000))" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="@Type" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="@Token" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </xsl:template>

    <xsl:template match="ssd:IdleEvents" mode="analysisTopLevel">
        <div>
            <xsl:attribute name="class">
                <xsl:text>analysis-container </xsl:text>
                <xsl:text>analysis-info</xsl:text>
            </xsl:attribute>
            <h1>
                <span class="expander">+ </span>System Idle Events
            </h1>
            <div class="analysis-body-collapsed">
                <xsl:choose>
                    <xsl:when test="count(ssd:Event) = 0">
                        <div class="analysis-empty">No system idle events present during this session.</div>
                    </xsl:when>
                    <xsl:otherwise>
                        <table class="pdc-phases">
                            <thead>
                                <th>EVENT</th>
                                <th>FROM START</th>
                                <th>TIME</th>
                            </thead>
                            <tbody>
                                <xsl:apply-templates select="ssd:Event" />
                            </tbody>
                        </table>
                    </xsl:otherwise>
                </xsl:choose>
            </div>
        </div>
    </xsl:template>

    <xsl:template match="ssd:Event">
        <tr>
            <xsl:attribute name="class">
                <xsl:text>row-info</xsl:text>
            </xsl:attribute>
            <td>
                <xsl:value-of select="@Info" />
            </td>
            <td class="center">
                <xsl:value-of select="js:formatDurationMs(string(@OffsetStart div 10000))" />
            </td>
            <td class="dateTime">
                <xsl:call-template name="formatDateTime">
                    <xsl:with-param name="dateTime" select="@LocalTimestamp" />
                </xsl:call-template>
            </td>
        </tr>
    </xsl:template>

    <xsl:template match="ssd:SmartUserPresenceInformation">
        <div>
            <xsl:attribute name="class">
                <xsl:text>analysis-container </xsl:text>
                <xsl:text>analysis-info</xsl:text>
            </xsl:attribute>
            <h1>
                <span class="expander">+ </span>
                Smart User Presence Prediction Information
            </h1>
            <div class="analysis-body-collapsed">
                <table class="defs">
                    <tr>
                        <td class="label">SUPPORTED</td>
                        <td class="label">GLOBAL USER PRESENT</td>
                        <td class="label">USER PREDICTION MODE</td>
                        <td class="label">MIN CONFIDENCE</td>
                        <td class="label">SUSPEND COUNT</td>
                        <td class="label">LAST USER AWAY END</td>
                    </tr>
                    <tr>
                        <td class="center">
                            <xsl:value-of select="ssd:Supported" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="ssd:GlobalUserPresent" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="ssd:UserPredictionMode" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="ssd:MinConfidence" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="ssd:SuspendCount" />
                        </td>
                        <td class="dateTime">
                            <xsl:call-template name="formatDateTime">
                                <xsl:with-param name="dateTime" select="ssd:LastUserAwayEndLocalTimestamp" />
                            </xsl:call-template>
                        </td>
                    </tr>
                </table>
                <xsl:apply-templates select="ssd:Intervals" mode="smartUserPresence" />
                <xsl:apply-templates select="ssd:Events" mode="smartUserPresence" />
            </div>
        </div>
    </xsl:template>
  
    <xsl:template match="ssd:Intervals" mode="smartUserPresence">
        <div>
            <xsl:attribute name="class">
                <xsl:text>analysis-container </xsl:text>
                <xsl:text>analysis-info</xsl:text>
            </xsl:attribute>
            <h1>
                <span class="expander">+ </span>Weekly Prediction Intervals
            </h1>
            <div class="analysis-body-collapsed">
                <xsl:choose>
                    <xsl:when test="count(ssd:UserIntervals)">
                        <xsl:apply-templates select="ssd:UserIntervals" />
                    </xsl:when>
                    <xsl:otherwise>
                        <div class="analysis-empty">No intervals.</div>
                    </xsl:otherwise>
                </xsl:choose>
            </div>
        </div>
    </xsl:template>
  
    <xsl:template match="ssd:UserIntervals">
        <div>
            <xsl:attribute name="class">
                <xsl:text>analysis-container </xsl:text>
                <xsl:text>analysis-info</xsl:text>
            </xsl:attribute>
            <h1>
                <span class="expander">+ </span>Intervals for User Sid
                <xsl:value-of select="ssd:UserSid" />
            </h1>
            <table class="defs">
                <tr>
                    <td class="label">INTERVAL NUMBER</td>
                    <td class="label">WEEKLY START OFFSET</td>
                    <td class="label">WEEKLY END OFFSET</td>
                    <td class="label">CONFIDENCE</td>
                </tr>
                <xsl:apply-templates select="ssd:Interval" mode="smartUserPresence" />
            </table>
            <div class="analysis-body-collapsed">
            </div>
        </div>
    </xsl:template>  
  
    <xsl:template match="ssd:Interval" mode="smartUserPresence">
        <tr>
            <td class="center">
                <xsl:value-of select="position()" />
            </td>
            <td class="center">
                <xsl:value-of select="js:formatDurationMs(string(ssd:WeeklyStartOffsetInUs div 1000))" />
            </td>
            <td class="center">
                <xsl:value-of select="js:formatDurationMs(string(ssd:WeeklyEndOffsetInUs div 1000))" />
            </td>
            <td class="center">
                <xsl:value-of select="ssd:Confidence" />
            </td>
        </tr>
    </xsl:template>  
  
    <xsl:template match="ssd:Events" mode="smartUserPresence">
        <div>
            <xsl:attribute name="class">
                <xsl:text>analysis-container </xsl:text>
                <xsl:text>analysis-info</xsl:text>
            </xsl:attribute>
            <h1>
                <span class="expander">+ </span>Events
            </h1>
            <div class="analysis-body-collapsed">
                <xsl:choose>
                    <xsl:when test="count(ssd:Event) = 0">
                        <div class="analysis-empty">No smart user presence events present during this session.</div>
                    </xsl:when>
                    <xsl:otherwise>
                        <table class="pdc-phases">
                            <thead>
                                <th>EVENT</th>
                                <th>FROM START</th>
                                <th>TIME</th>
                            </thead>
                            <tbody>
                                <xsl:apply-templates select="ssd:Event" />
                            </tbody>
                        </table>
                    </xsl:otherwise>
                </xsl:choose>
            </div>
        </div>
    </xsl:template>

    <xsl:template match="ssd:SleepIntervals" mode="analysisTopLevel">
        <div>
            <xsl:attribute name="class">
                <xsl:text>analysis-container </xsl:text>
                <xsl:text>analysis-info</xsl:text>
            </xsl:attribute>
            <h1>
                <span class="expander">+ </span>Sleep Intervals
            </h1>
            <div class="analysis-body-collapsed">
                <xsl:choose>
                    <xsl:when test="count(ssd:SleepInterval)">
                        <xsl:apply-templates select="ssd:SleepInterval" />
                    </xsl:when>
                    <xsl:otherwise>
                        <div class="analysis-empty">The system did not sleep during this session.</div>
                    </xsl:otherwise>
                </xsl:choose>
            </div>
        </div>
    </xsl:template>

    <xsl:template match="ssd:SleepInterval">
        <div>
            <xsl:attribute name="class">
                <xsl:text>analysis-container </xsl:text>
                <xsl:text>analysis-</xsl:text>
                <xsl:choose>
                    <xsl:when test="@ProbablyClean = '1'">low</xsl:when>
                    <xsl:otherwise>high</xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
            <h1>
                <span class="expander">+ </span>
                <xsl:value-of select="js:createSleepIntervalString(string(@State))" />
            </h1>
            <div class="analysis-body-collapsed">
                <table class="defs">
                    <tr>
                        <td class="label">START TIME</td>
                        <td class="label">DURATION</td>
                        <td class="label">STATE</td>
                        <td class="label">ACTION</td>
                        <td class="label">REASON</td>
                        <td class="label">ID</td>
                        <td class="label">STATUS</td>
                        <td class="label">SUCCESSFUL</td>
                    </tr>
                    <tr>
                        <td class="percent">
                            <xsl:value-of select="@LocalStartTime" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="js:formatDurationMs(string(@Duration div 10000))" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="js:createSleepIntervalString(string(@State))" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="@Action" />
                        </td>
                        <td class="center">
                            <xsl:call-template name="toSleepStartReason">
                                <xsl:with-param name="reason" select="@Reason" />
                            </xsl:call-template>
                        </td>
                        <td class="center">
                            <xsl:value-of select="@Id" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="@Status" />
                        </td>
                        <td class="center">
                            <xsl:value-of select="@ProbablyClean" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </xsl:template>

    <!-- Matches the root node. This starts the XSL processing. -->
    <xsl:template match="/" >

        <html>
            <head>
                <!-- Support the latest IE -->
                <meta http-equiv="X-UA-Compatible" content="IE=edge" />

                <!-- All times are displayed using local time. Store the offset at which the report was generated in
             case someone needs to calculate the UTC times (although this is not entirely sufficient if the
             machine has moved timezones during the report period. -->
                <meta name="ReportUtcOffset" content="{$reportInfo/ssd:UtcOffset}" />

                <title>System Sleep Diagnostics</title>

                <!-- CSS styles -->
                <xsl:call-template name="css"/>

                <!-- JavaScript -->
                <xsl:call-template name="javascript">
                    <xsl:with-param name="idleTimes" select="/ssd:SystemSleepDiagnostics/ssd:UserAbsenceSessions/ssd:Session/ssd:Runtime/ssd:IdleTime" />
                </xsl:call-template>

            </head>

            <body>

                <h1>System Sleep Diagnostics</h1>

                <!-- Describe the machine -->
                <xsl:call-template name="systemInformation" />

                <!-- Summary Table -->
                <h2>User Not Present Intervals</h2>
                <xsl:apply-templates select="/ssd:SystemSleepDiagnostics/ssd:UserAbsenceSessions" mode="summaryTable" />

                <!-- Analysis results -->
                <h2>Analysis Results</h2>
                <div class="explanation">Analysis of intervals where the user went away and the machine might not have slept when the user expected it to.</div>
                <xsl:apply-templates select="/ssd:SystemSleepDiagnostics/ssd:UserAbsenceSessions" mode="analysisResults" />

                <br />
                <br />
                <br />
            </body>
        </html>
    </xsl:template>

    <ms:script implements-prefix="js">
        <![CDATA[
    // Formats a number using the current locale (to handle the 1000's separator).
    // The result is rounded so no decimal point is shown.
    function numberToLocaleString(value) {
      var localeString = Math.round(parseFloat(value + '')).toLocaleString();
      return localeString.substring(0, localeString.indexOf('.'));
    }

    function padLeft(number, length) {
      var str = '' + number;
      while (str.length < length) {
        str = '0' + str;
      }
      return str;
    }

    var dateFormat = /(\d{4})-(\d{2})-(\d{2})[T](\d{2}):(\d{2}):(\d{2})/

    // Parses a date-time string and returns a Date (i.e. number of milliseconds)
    function parseDateTime(value) {
      if (!value) {
        return 0;
      }
      var match = dateFormat.exec(value)
      if (!match) {
        return 0;
      }
      return Date.parse(match[1] + '/' + match[2] + '/' + match[3] + ' ' + match[4] + ':' + match[5] + ':' + match[6])
    }

    // Parses just the date portion of a date-time string and returns a Date (i.e. number of milliseconds)
    function parseDate(value) {
      if (!value) {
        return 0;
      }
      var match = dateFormat.exec(value)
      if (!match) {
        return 0;
      }
      return Date.parse(match[1] + '/' + match[2] + '/' + match[3])
    }

    var durationFormat = /P((\d+)D)?T((\d+)H)?((\d+)M)?(\d+)S/

    // Convert a string of the form P10DT1H15M40S to a count of milliseconds
    function parseDurationToMs(value) {
      var match = durationFormat.exec(value)
      if (!match) {
        return 0
      }
      var days = parseInt(match[2] || '0');
      var hrs = parseInt(match[4] || '0');
      var mins = parseInt(match[6] || '0');
      var secs = parseInt(match[7] || '0');
      return ((((((days * 24) + hrs) * 60) + mins) * 60) +  secs) * 1000;
    }

    // Formats a number of milliseconds as h:mm:ss
    function formatDurationMs(value) {
      var ms = parseInt(value);
      var secs = ms / 1000;
      var mins = secs / 60;
      var hrs = Math.floor(mins / 60);
      mins = Math.floor(mins % 60);
      secs = Math.floor(secs % 60);
      return hrs + ':' + padLeft(mins,2) + ':' + padLeft(secs,2);
    }

    // Converts a string representing a date time to a day and month string
    function dateToDayAndMonth(date, dayOffset) {
      var adjustedDate = new Date(parseDate(date) - (dayOffset * 24 * 60 * 60 * 1000));
      return padLeft(adjustedDate.toLocaleDateString());
    }


    // Format sleep interval strings to present a more friendly name in the
    // report.
    function createSleepIntervalString(state) {
        var _state = parseInt(state); // SYSTEM_POWER_STATE
        var str;

        if (_state == 1) {
            str = 'Working';
        } else if (_state == 2) {
            str = 'Sleeping1';
        } else if (_state == 3) {
            str = 'Sleeping2';
        } else if (_state == 4) {
            str = 'Sleeping3';
        } else if (_state == 5) {
            str = 'Hibernate';
        } else if (_state == 6) {
            str = 'Shutdown';
        } else {
            str = 'Invalid';
        }

        return str;
    }
    ]]>
    </ms:script>
</xsl:stylesheet>
P<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ms="urn:schemas-microsoft-com:xslt"
    xmlns:slp="http://schemas.microsoft.com/sleepstudy/2012"
    xmlns:js="http://microsoft.com/kernel"
    version="1.0">

  <xsl:output
      method="html"
      omit-xml-declaration="yes"
      indent="no"
      encoding="utf-16" />

  <xsl:variable name="reportInfo" select="/slp:SleepStudy/slp:ReportInformation" />
  <xsl:variable name="systemInfo" select="/slp:SleepStudy/slp:SystemInformation" />
  <xsl:variable name="reportTime" select="string($reportInfo/slp:ScanTime)" />
  <xsl:variable name="localReportTime" select="string($reportInfo/slp:LocalScanTime)" />
  <xsl:variable name="aoac" select="$systemInfo/slp:ConnectedStandby != 0"/>
  <xsl:variable name="reportDuration" select="$reportInfo/slp:ReportDuration" />
  <xsl:variable name="graphStart" select="$reportInfo/slp:LocalReportStartTime" />
  <xsl:variable name="singleTraceFile" select="$reportInfo/slp:SingleTraceFile" />

  <!-- Styles -->
  <xsl:template name="css">
    <style type="text/css">
      body {
      font-family: Segoe UI Light;
      letter-spacing: 0.02em;
      background-color: #ffffff;
      color: #000000;
      margin: 0em 5.5em 0em 5.5em;
      }

      h1 {
      color: #00b0f0;
      font-size: 42pt;
      }

      h2 {
      font-size: 15pt;
      color: #00b0f0;
      margin-top: 2em;
      margin-bottom: 0em;
      letter-spacing: 0.08em;
      }

      h3, h4, h5 {
      margin-top: 1em;
      margin-bottom: 0em;
      letter-spacing: 0.08em;
      }

      td {
      padding-left: 0.3em;
      padding-right: 0.3em;
      }

      .nobatts {
      margin-top: 1.5em;
      font-family: Segoe UI Semibold;
      background: #f0f0f0;
      color: #a0a0a0;
      font-size: 13pt;
      padding-left:0.4em;
      padding-right:0.4em;
      padding-top:0.3em;
      padding-bottom:0.3em;
      }

      .explanation {
      color: #777777;
      font-size: 12pt;
      margin-bottom: 1em;
      }

      .explanation2 {
      color: #777777;
      font-size: 12pt;
      margin-bottom: 0.1em;
      }

      table {
      border-width: 0;
      table-layout: fixed;
      font-family: Segoe UI Light;
      letter-spacing: 0.02em;
      color: #000000;
      margin-bottom: 10px;
      }

      table.defs { background-color: transparent; }

      caption {
      padding: 5px 0px 5px 0px;
      font-weight: bold;
      }

      thead {
      font-family: Segoe UI Semibold;
      font-size: 85%;
      }

      text {
      font-size: 12pt;
      font-family: Segoe UI Light;
      fill: #00b0f0;
      }

      .centered { text-align: center; }

      .label {
      font-family: Segoe UI Semibold;
      font-size: 85%;
      color: #acacac;
      }

      .labeldetails {
      text-indent: 40px;
      font-family: Segoe UI Semibold;
      font-size: 85%;
      color: #acacac;
      }

      #legend {
      background-color: #fafafa;
      margin-bottom: 2.2em;
      border-spacing: 0;
      }

      #legend thead { background-color: #dfdfdf; }
      #legend td, #legend th {
      padding: 4px 5px 4px 5px;
      }

      #legend .spanner {
      text-align: center;
      background-color: #dfdfdf;
      font-size: 85%;
      font-weight: bold;
      padding: 3px;
      }

      #legend td.percent { text-align: left; }

      .graphline-none, .graphline-dotted, .graphline-solid, .graphline-neutral,
      .graphline-low, .graphline-moderate, .graphline-high .graphline-nonclean {
      font-weight: bold;
      }

      .graphline-none { color: #7d7d7d; }
      .graphline-dotted { color: #7d7d7d; }
      .graphline-solid { color: #7d7d7d; }
      .graphline-neutral { color: #7d7d7d; }
      .graphline-low { color: #2a7a2a; }
      .graphline-moderate { color: #cc7e06; }
      .graphline-high { color: #970d00; }
      .graphline-nonclean { color: #FF00FF;}

      .top-blocker td, #summary-table td {
      padding: 0;
      }

      .top-blocker td a, #summary-table td a {
      padding: 0 0.3em 0 0.3em;
      display: block;
      height: 100%;
      }

      .top-blocker a:link, .top-blocker a:active, .top-blocker a:visited,
      #summary-table a:link, #summary-table a:active, #summary-table a:visited {
      text-decoration: none;
      color: #000000;
      }

      #summary-table th,
      .session-summary th,
      .top-blocker th,
      .pdc-phases th,
      .device-components th {
      background-color: transparent;
      }

      #summary-table tbody tr,
      .session-summary tbody tr,
      .top-blocker tbody tr,
      .device-components tbody tr,
      .pdc-phases tbody tr {
      background-color: #e0e0e0;
      }

      #summary-table .row-neutral,
      .session-summary .row-neutral,
      .top-blocker .row-neutral,
      .device-components .row-neutral,
      .pdc-phases .row-neutral {
      background-color: #e0e0e0;
      }

      #summary-table .row-low,
      .session-summary .row-low,
      .top-blocker .row-low,
      .device-components .row-low,
      .pdc-phases .row-low {
      background-color: #ace3ac;
      }

      #summary-table .row-moderate,
      .session-summary .row-moderate,
      .top-blocker .row-moderate,
      .device-components .row-moderate,
      .pdc-phases .row-moderate {
      background-color: #fcd69a;
      }

      #summary-table .row-high,
      .session-summary .row-high,
      .top-blocker .row-high,
      .device-components .row-high,
      .pdc-phases .row-high {
      background-color: #ffb2aa;
      }

      #summary-table .row-info,
      .session-summary .row-info,
      .top-blocker .row-info,
      .device-components .row-info,
      .pdc-phases .row-info {
      background-color: #86becb;
      }

      #summary-table .row-nonclean,
      .session-summary .row-nonclean,
      .top-blocker .row-nonclean,
      .device-components .row-nonclean,
      .pdc-phases .row-nonclean {
      background-color: #EE82EE;
      }

      #summary-table tbody tr:hover,
      .top-blocker tbody tr:hover {
      background-color: #f0f0f0;
      }

      #summary-table .row-neutral:hover,
      .top-blocker .row-neutral:hover {
      background-color: #f0f0f0;
      }

      #summary-table .row-low:hover,
      .top-blocker .row-low:hover {
      background-color: #caedca;
      }

      #summary-table .row-moderate:hover,
      .top-blocker .row-moderate:hover {
      background-color: #fde5c0;
      }

      #summary-table .row-high:hover,
      .top-blocker .row-high:hover {
      background-color: #ffd5d1;
      }

      #summary-table .row-nonclean:hover,
      .top-blocker .row-nonclean:hover {
      background-color:#D8BFD8;
      }

      td.colBreak { padding: 0; width: 0.15em; }

      td.state { text-align: center; }
      td.chargeOrDrain { text-align: center; }
      td.percentLowPowerStateTime { text-align: center; }
      td.percent { font-family: Segoe UI Symbol; text-align: center; }
      td.hms { font-family: Segoe UI Symbol; text-align: center; }
      td.dateTime { font-family: Segoe UI Symbol; }
      td.blank { background-color: #ffffff; }
      td.nullValue { text-align: center; }
      td.center { text-align: center; }

      col.percent { width: 7.5em; }

      td.mw {
      font-family: Segoe UI Symbol;
      text-align: center;
      }

      td.acdc { text-align: center; }

      span.date {
      display: inline-block;
      width: 5.5em;
      }

      span.time {
      text-align: right;
      width: 4.2em;
      display: inline-block;
      }

      text { font-family: Segoe UI Symbol; }

      .noncontigbreak {
      height: 0.3em;
      background-color: #1A1A28;
      }

      div.analysis-container {
      margin-bottom: 10px;
      border: 1px solid #ffffff;
      }

      div.analysis-container h1 {
      padding: 10px;
      font-size: 14px;
      margin: 0px;
      cursor: pointer;
      }

      div.analysis-body, div.analysis-body-collapsed {
      padding: 10px;
      }

      div.analysis-body { display: block; }
      div.analysis-body-collapsed { display: none; }

      .analysis-base { background-color: #f7f7f7; }
      .analysis-base h1 { color: #a0a0a0; background-color: #d0d0d0; }
      .analysis-base h1:hover { background-color: #dfdfdf; }

      .analysis-neutral { background-color: #f0f0f0; }
      .analysis-neutral h1 { color: #a0a0a0; background-color: #d0d0d0; }
      .analysis-neutral h1:hover { background-color: #dfdfdf; }

      .analysis-high { background-color: #ffd5d1; }
      .analysis-high h1 { background-color: #ff8e83; color: #970d00; }
      .analysis-high h1:hover { background-color: #ffb2aa; }

      .analysis-moderate { background-color: #fde5c0; }
      .analysis-moderate h1 { background-color: #fbc674; color: #cc7e06; }
      .analysis-moderate h1:hover { background-color: #fcd69a; }

      .analysis-low { background-color: #caedca; }
      .analysis-low h1 { background-color: #8fd98f; color: #2a7a2a; }
      .analysis-low h1:hover { background-color: #ace3ac; }

      .analysis-info { background-color: #b2e5e5; }
      .analysis-info h1 { background-color: #1aa3a3; color: #0b5e56; }
      .analysis-info h1:hover { background-color: #86becb; }

      .analysis-empty {
      color: #a0a0a0;
      font-size: 14px;
      padding: 10px;
      font-weight: bold;
      }
    </style>
    <!-- split the css into two style tags to get around the locstudio 8192 character limit -->
    <style>
      .expander { font-family: "Consolas"; font-weight: bold; }
      .warning { background-color: #fde5c0; }
      .warning h1 { background-color: #fbc674; color: #cc7e06; }
      .warning h1:hover { background-color: #fcd69a; }
      .error { background-color: #ffd5d1; }
      .error h1 { background-color: #ff8e83; color: #970d00; }
      .error h1:hover { background-color: #ffb2aa; }
      code { font-family: "Consolas"; }

      pre {
      font-family: "Consolas";
      display: block;
      border: 1px dashed #b0b0b0;
      padding: 10px;
      margin: 10px 0px 10px 0px;
      }

      .scroll-top-button {
      border: 2px solid #000000;
      background-color: #ffffff;
      padding: 5px 3px 5px 3px;
      font-size: 12px;
      font-family: Segoe UI Semibold;
      float: left;
      border-radius: 18px;
      margin-top: 15px;
      margin-left: -60px;
      }

      .scroll-top-button:hover {
      background-color: #f0f0f0;
      cursor: pointer;
      }

      .scenario-details, .scenario-details-collapsed {
      padding: 5px;
      background-color: #f0f0f0;
      width: 864px;
      border-left: 2px solid #ffffff;
      }

      .scenario-details { display: block; }
      .scenario-details-collapsed { display: none; }

      .details-expander {
      background-color: #dfdfdf;
      font-weight: bold;
      cursor: pointer;
      }

      .details-expander:hover { background-color: #cfcfcf; }

      ul { list-style: square; }
    </style>
  </xsl:template>

  <!-- JavaScript for the page -->
  <xsl:template name="jsUtil">
    <xsl:text disable-output-escaping="yes">
    // Add support for drawing dashed lines to Canvas
    CanvasRenderingContext2D.prototype.dashedLine = function (x0, y0, x1, y1, dashArray) {
        if (dashArray == null) {
            dashArray = [4, 4];
        }

        var dx = x1 - x0;
        var dy = y1 - y0;
        var distance = Math.sqrt(Math.pow((x1 - x0), 2) + Math.pow((y1 - y0), 2));
        var theta = Math.atan(dy / dx);
        if (dx &lt; 0) {
            theta += Math.PI;
        }

        var i = 0;
        while (distance &gt; 0) {
            var length = Math.min(distance, dashArray[i]);
            x0 += length * Math.cos(theta);
            y0 += length * Math.sin(theta);
            if (i % 2 == 0) {
                this.lineTo(x0, y0);

            } else {
                this.moveTo(x0, y0);
            }

            distance -= length;
            i = (i + 1) % dashArray.length;
        }
    };
    </xsl:text>
  </xsl:template>

  <xsl:template name="jsDateUtil">
    <xsl:text disable-output-escaping="yes">
    // Formats a number using the current locale (to handle the 1000's separator).
    // The result is rounded so no decimal point is shown.
    function numberToLocaleString(value) {
        var localeString = Math.round(parseFloat(value + '')).toLocaleString();
        return localeString.substring(0, localeString.indexOf('.'));
    }

    function padLeft(number, length) {
        var str = '' + number;
        while (str.length &lt; length) {
            str = '0' + str;
        }

        return str;
    }

    // Returns the number of milliseconds between 2 date-times represented as strings.
    function msBetween(startTime, endTime) {
        return startTime &gt; endTime
               ? msBetween(endTime, startTime)
               : parseDateTime(endTime) - parseDateTime(startTime);
    }

    var dateFormat = /(\d{4})-(\d{2})-(\d{2})[T](\d{2}):(\d{2}):(\d{2})/

    // Parses a date-time string and returns a Date (i.e. number of milliseconds)
    function parseDateTime(value) {
        if (!value) {
            return 0;
        }

        var match = dateFormat.exec(value)
        if (!match) {
            return 0;
        }

        return Date.parse(match[1] + '/' + match[2] + '/' +
                          match[3] + ' ' + match[4] + ':' +
                          match[5] + ':' + match[6])
    }

    // Parses just the date portion of a date-time string and returns a Date
    // (i.e. number of milliseconds)
    function parseDate(value) {
        if (!value) {
            return 0;
        }

        var match = dateFormat.exec(value)
        if (!match) {
            return 0;
        }

        return Date.parse(match[1] + '/' + match[2] + '/' + match[3])
    }

    var durationFormat = /P((\d+)D)?T((\d+)H)?((\d+)M)?(\d+)S/

    // Convert a string of the form P10DT1H15M40S to a count of milliseconds
    function parseDurationToMs(value) {
        var match = durationFormat.exec(value)
        if (!match) {
            return 0
        }

        var days = parseInt(match[2] || '0');
        var hrs = parseInt(match[4] || '0');
        var mins = parseInt(match[6] || '0');
        var secs = parseInt(match[7] || '0');
        return ((((((days * 24) + hrs) * 60) + mins) * 60) +  secs) * 1000;
    }

    // Converts milliseconds to days
    function msToDays(ms) {
        return (ms / 1000 / 60 / 60 / 24);
    }

    function daysToMs(days) {
        return (days * 24 * 60 * 60 * 1000);
    }

    // Formats a number of milliseconds as h:mm:ss
    function formatDurationMs(value) {
        var ms = parseInt(value);
        var secs = ms / 1000;
        var mins = secs / 60;
        var hrs = Math.floor(mins / 60);
        mins = Math.floor(mins % 60);
        secs = Math.floor(secs % 60);
        return hrs + ':' + padLeft(mins,2) + ':' + padLeft(secs,2);
    }

    // Converts a millisecond timestamp to a day and month string
    // Note: dayOffset is forward from date.
    function dateToDayAndMonth(ms, dayOffset) {
        var adjustedDate = new Date(ms + (dayOffset * 24 * 60 * 60 * 1000));
        return padLeft(adjustedDate.getMonth() + 1, 2) + "-" +
               padLeft(adjustedDate.getDate(), 2);
    }

    // Takes a millisecond timestamp and returns a new millisecond timestamp
    // rounded down to the current day.
    function dateFloor(ms) {
        var dt = new Date(ms);
        return Date.parse(dt.getFullYear() + '/' + (dt.getMonth() + 1) + '/' + dt.getDate());
    }

    var osstate = "All";
    var duration = "Alltime";

  // Actions values based on os power state radio button selection.
  function osStateValueChanged() {
    if (document.getElementById('is_bug_session').checked) {
        osstate = document.getElementById("is_bug_session").value;
    } else if (document.getElementById('is_all_session').checked) {
        osstate = document.getElementById("is_all_session").value;
    } else if (document.getElementById('is_shutdown_session').checked) {
        osstate = document.getElementById("is_shutdown_session").value;
    } else if (document.getElementById('is_screenoff_session').checked) {
        osstate = document.getElementById("is_screenoff_session").value;
    } else if (document.getElementById('is_sleep_session').checked) {
        osstate = document.getElementById("is_sleep_session").value;
    } else if (document.getElementById('is_hib_session').checked) {
        osstate = document.getElementById("is_hib_session").value;
    } else if (document.getElementById('is_active_session').checked) {
        osstate = document.getElementById("is_active_session").value;
    }

    searchTable(osstate, duration);
  }

  // Actions values based on "duration" radio button selection.
  function durationValueChanged() {
    if (document.getElementById('is_all_time').checked) {
        duration = document.getElementById("is_all_time").value;

    } else if (document.getElementById('is_10_session').checked) {
        duration = document.getElementById("is_10_session").value;
    }

    searchTable(osstate, duration);
  }

  // Summary table selection logic based on radio button selection.
  function searchTable(osstate, duration) {
    var foundstate, foundduration, table, tr, td, i, j, k;
    table = document.getElementById("summary-table");
    tr = table.getElementsByTagName("tr");
    for (i = 0; i &lt; tr.length; i++) {
        td = tr[i].getElementsByTagName("td");
        //TODO: to optimize this we need to use getElementsByClassName.
        for (j = 0; j &lt; td.length; j++) {
            if (td[j].className == "hms") {
                if (duration == "10:00") {
                    var dur = td[j].textContent;
                    var HourNum = parseInt(dur);
                    var subduration = dur.substr(dur.indexOf(":") + 1);
                    var MinNum = parseInt(subduration);
                    if (HourNum >=1 || MinNum >= 10) {
                        foundduration = true;
                    }
                }
            }

            if ((osstate != "All") &amp;&amp; td[j].className == "state") {
                // in case of shutdown compare with all shutdown variant.
                if ((osstate == "Shutdown")) {
                    if ((td[j].textContent == "Shutdown") || (td[j].textContent == "Shutdown (Hybrid)")) {
                        foundstate = true;
                    }
                }
                // in case of standby AoAc or S3, compare sleep
                if ((osstate == "Standby")) {
                    if ((td[j].textContent == "Sleep") || (td[j].textContent == "Sleep (Hybrid)")) {
                        foundstate = true;
                    }
                }
                // in case of screen off, compare screen off.
                if ((osstate == "ScreenOff")) {
                    if ((td[j].textContent == "Screen Off")) {
                        foundstate = true;
                    }
                }

                if (osstate == "Bug Check") {
                    if ((td[j].textContent == "Bugcheck") || (td[j].textContent == "Abnormal Shutdown")) {
                        foundstate = true;
                    }

                } else if (td[j].textContent == osstate) {
                    foundstate = true;
                }
            }
        } // end of inner for loop.

        // make decision what to show and what to hide.
        if (duration == "10:00" &amp;&amp; (osstate != "All")) {
            if (foundstate &amp;&amp; foundduration) {
                tr[i].style.display = "";
                foundstate = false;
                foundduration = false;

            } else {
                if (td.length) {
                    tr[i].style.display = "none";
                }
            }
        }

        if (duration == "10:00" &amp;&amp; (osstate == "All")) {
            if (foundduration) {
                tr[i].style.display = "";
                foundstate = false;
                foundduration = false;

            } else {
                if (td.length) {
                    tr[i].style.display = "none";
                }
            }
        }

        if (duration == "Alltime" &amp;&amp; (osstate == "All")) {
            tr[i].style.display = "";
            foundstate = false;
            foundduration = false;
        }

        if (duration == "Alltime" &amp;&amp; (osstate != "All")) {
            if (foundstate) {
                tr[i].style.display = "";
                foundstate = false;
                foundduration = false;

            } else {
                if (td.length) {
                    tr[i].style.display = "none";
                }
            }
        }

        foundstate = false;
        foundduration = false;
    }
}
    </xsl:text>
  </xsl:template>

  <xsl:template name="jsTimegraph">
    <xsl:text disable-output-escaping="yes">
    Timegraph = {
        axisTop: 9.5,
        axisRight: 24.5,
        axisBottom: 25.5,
        axisLeft: 25.5,
        ticks: 10,

        // Maximum number of 24 hour ticks for showing 12 and 6 hour ticks

        ticks12Hour: 8,
        ticks6Hour: 4,

        // Shading

        shadingColor: "#d0d0d0",

        precompute: function (graph) {
            var canvas = graph.canvas;
            var data = graph.data;
            var min = 0;
            var max = 0;

            graph.height = canvas.height - Timegraph.axisTop - Timegraph.axisBottom;
            graph.width = canvas.width - Timegraph.axisLeft - Timegraph.axisRight;
            for (var i = 0; i &lt; data.length; i++) {
                data[i].t0 = parseDateTime(data[i].x0);
                data[i].t1 = parseDateTime(data[i].x1);

                if (i == 0) {
                    min = data[i].t0;
                    max = data[i].t1;
                }

                if (data[i].t0 &lt; min) {
                    min = data[i].t0;
                }

                if (data[i].t1 &gt; max) {
                    max = data[i].t1;
                }

                data[i].yy0 =
                    Timegraph.axisTop + graph.height - data[i].y0 * graph.height;

                data[i].yy1 =
                    Timegraph.axisTop + graph.height - data[i].y1 * graph.height;
            }

            if (graph.startTime != null) {
                graph.startMs = parseDateTime(graph.startTime);

            } else {
                graph.startMs = min;
            }

            graph.endMs = max;
            graph.durationMs = max - min;
        },

        drawFrame: function (graph) {
            var canvas = graph.canvas;
            var context = graph.context;

            graph.width =
                canvas.width - Timegraph.axisRight - Timegraph.axisLeft;

            graph.height =
                canvas.height - Timegraph.axisTop - Timegraph.axisBottom;

            context.beginPath();
            context.moveTo(Timegraph.axisLeft, Timegraph.axisTop);
            context.lineTo(Timegraph.axisLeft + graph.width,
                           Timegraph.axisTop);

            context.lineTo(Timegraph.axisLeft + graph.width,
                           Timegraph.axisTop + graph.height);

            context.lineTo(Timegraph.axisLeft,
                           Timegraph.axisTop + graph.height);

            context.lineTo(Timegraph.axisLeft, Timegraph.axisTop);
            context.strokeStyle = "#c0c0c0";
            context.stroke();
        },

        drawRange: function (graph) {
            var canvas = graph.canvas;
            var context = graph.context;

            context.font = "12pt Segoe UI";
            context.fillStyle = "#00b0f0";
            context.fillText("%", 0, Timegraph.axisTop + 5, Timegraph.axisLeft);

            var tickSpacing = graph.height / 10;
            var offset = Timegraph.axisTop + tickSpacing;
            var tickValue = 90;
            for (var i = 0; i &lt; 9; i++) {
                context.beginPath();
                context.moveTo(Timegraph.axisLeft, offset);
                context.lineTo(Timegraph.axisLeft + graph.width,
                               offset);

                context.stroke();
                context.fillText(tickValue.toString(),
                                 0,
                                 offset + 5,
                                 Timegraph.axisLeft);

                offset += tickSpacing;
                tickValue -= 10;
            }
        },

        drawDomain: function (graph, start, end) {
            var canvas = graph.canvas;
            var context = graph.context;
            var data = graph.data;
            var duration = end - start;
            if ((end &lt; start)) {
                return;
            }

            var startDay = dateFloor(start);
            var t0 = startDay;
            var t1 = dateFloor(end);
            var dayOffset = 0;
            if (start &gt; t0) {
                t0 = t0 + daysToMs(1);
                dayOffset++;
            }

            if (t0 &gt;= t1) {
                return;
            }

            var increment =
                Math.max(Math.floor((t1 - t0) / daysToMs(Timegraph.ticks)), 1);

            var incrementMs = daysToMs(increment);
            var spacing = (incrementMs / duration) * graph.width;
            var offset = (t0 - start) / duration;
            var ticksCount = Math.floor((t1 - t0) / incrementMs);
            for (offset = offset * graph.width + Timegraph.axisLeft;
                 offset &lt; (graph.width + Timegraph.axisLeft);
                 offset += spacing) {

                context.beginPath();
                context.moveTo(offset, Timegraph.axisTop);
                context.lineTo(offset, Timegraph.axisTop + graph.height);
                context.stroke();
                context.fillText(dateToDayAndMonth(startDay, dayOffset),
                                 offset,
                                 Timegraph.axisTop + graph.height + 15,
                                 spacing);

                dayOffset += increment;
            }
        },

        plot: function (graph, start, end) {
            var canvas = graph.canvas;
            var context = graph.context
            var data = graph.data;

            if ((end &lt; start)) {
                return;
            }

            var duration = end - start;
            Timegraph.drawDomain(graph, start, end);
            context.fillStyle = Timegraph.shadingColor;
            for (var i = 0; i &lt; data.length - 1; i++) {
                if ((data[i].t0 &lt; start) || (data[i].t0 &gt; end) ||
                    (data[i].t1 &gt; end)) {

                    continue;
                }

                var x1 = (data[i].t0 - start) / duration;
                x1 = x1 * graph.width + Timegraph.axisLeft;

                var x2 = (data[i].t1 - start) / duration;
                x2 = x2 * graph.width + Timegraph.axisLeft;

                context.globalAlpha = 0.3;
                context.fillRect(x1, Timegraph.axisTop, (x2 - x1), graph.height);
                context.globalAlpha = 1;
                context.beginPath();
                context.strokeStyle = graph.lineTypes[data[i].type].color;
                context.lineWidth = 1.5;
                if (graph.lineTypes[data[i].type].dotted == 1) {
                    context.dashedLine(x1, data[i].yy0, x2, data[i].yy1);

                } else {
                    context.moveTo(x1, data[i].yy0);
                    context.lineTo(x2, data[i].yy1);
                }

                context.stroke();
            }
        },

        draw: function (graph) {
            var canvas = document.getElementById(graph.element);
            if (canvas == null) {
                return;
            }

            var context = canvas.getContext('2d');
            if (context == null) {
                return;
            }

            graph.width = 0;
            graph.height = 0;
            graph.context = context;
            graph.canvas = canvas;

            Timegraph.precompute(graph);
            Timegraph.drawFrame(graph);
            Timegraph.drawRange(graph);
            Timegraph.plot(graph, graph.startMs, graph.endMs);
        }
    };
    </xsl:text>
  </xsl:template>

  <xsl:template name="jsHistogram">
    <xsl:text disable-output-escaping="yes">
    Histogram = {

        // Constants

        yTicks: 10,
        axisLeft: 30.5,
        axisBottom: 25.5,
        paddingTop: 5,
        maxPadding: 25,
        barColor: "#1191c1",

        // Functions

        precompute: function (graph) {
            var canvas = graph.canvas;
            var bucketCount = 0;
            for (var i = 0; i &lt; graph.data.length; i++) {
                if (graph.data[i].value > graph.max) {
                    graph.max = graph.data[i].value;
                }

                bucketCount++;
            }

            if (graph.rangeMax != null) {
                graph.max = Math.max(graph.max, graph.rangeMax);
            }

            graph.bucketCount = bucketCount;
            graph.tickSpacing = (canvas.width - Histogram.axisLeft) / bucketCount;
            graph.height = canvas.height;
            graph.width = canvas.width;
        },

        drawFrame: function (graph) {
            var context = graph.context;
            var canvas = graph.canvas;

            context.beginPath();
            context.moveTo(Histogram.axisLeft, Histogram.paddingTop);
            context.lineTo(Histogram.axisLeft,
                           canvas.height - Histogram.axisBottom);

            context.lineTo(canvas.width,
                           canvas.height - Histogram.axisBottom);

            context.stroke();
        },

        drawDomain: function (graph) {
            var context = graph.context;
            var tickOffset = 0;

            context.font = "8pt Segoe UI";
            context.fillStyle = "#00b0f0";
            for (var i = 0; i &lt; graph.bucketCount; i++) {
                context.fillText(graph.data[i].interval,
                                 Histogram.axisLeft + tickOffset + 2,
                                 graph.height - 10,
                                 graph.tickSpacing);

                tickOffset += graph.tickSpacing;
            }
        },

        drawRange: function (graph) {
            var context = graph.context;
            var tickSpacing = (graph.height - Histogram.axisBottom - 25) /
                              Histogram.yTicks;

            var tickIncrement = Math.round(graph.max / Histogram.yTicks);
            var tickOffset = graph.height - Histogram.axisBottom -
                             tickSpacing;

            var tickValue = tickIncrement;
            context.font = "12pt Segoe UI";
            context.fillStyle = "#00b0f0";
            for (var i = 0; i &lt; Histogram.yTicks; i++) {
                context.beginPath();
                context.moveTo(Histogram.axisLeft, tickOffset);
                context.lineTo(Histogram.axisLeft + 5, tickOffset);
                context.stroke();
                context.fillText(tickValue.toString(),
                                 0,
                                 tickOffset + 5,
                                 Histogram.axisLeft);

                tickValue += tickIncrement;
                tickOffset -= tickSpacing;
            }
        },

        plot: function (graph) {
            var tickOffset = 0;
            var context = graph.context;
            context.fillStyle = Histogram.barColor;
            for (var i = 0; i &lt; graph.bucketCount; i++) {
                if (graph.data[i].value == 0) {
                    tickOffset += graph.tickSpacing;;
                    continue;
                }

                var barHeight =
                    Math.round((graph.data[i].value * (graph.height - 50)) / graph.max);

                context.fillRect(Histogram.axisLeft + tickOffset + Histogram.paddingTop,
                                 graph.height - Histogram.axisBottom - barHeight,
                                 graph.tickSpacing - 10,
                                 barHeight);

                tickOffset += graph.tickSpacing;
            }
        },

        draw: function (graph) {
            var canvas = document.getElementById(graph.element);
            if (canvas == null) {
                return;
            }

            var context = canvas.getContext("2d");
            if (context == null) {
                return;
            }

            if (graph.data == null) {
                return;
            }

            graph.bucketCount = 0;
            graph.max = 0;
            graph.tickSpacing = 0;
            graph.width = 0;
            graph.height = 0;
            graph.context = context;
            graph.canvas = canvas;

            context.strokeStyle = "#c0c0c0";

            Histogram.precompute(graph);
            Histogram.drawFrame(graph);
            Histogram.drawRange(graph);
            Histogram.drawDomain(graph);
            Histogram.plot(graph);
        }
    };
    </xsl:text>
  </xsl:template>

  <xsl:template name="jsCollapser">
    <xsl:text disable-output-escaping="yes">
    Collapser = {
        topActiveBlockerDivs: {},
        detailsContainers: {},

        getContainerBody: function (container) {
            var children = container.childNodes;
            var containerBody = null;
            for (var i = 0; i &lt; children.length; i++) {
                if (children[i].tagName == "DIV" &amp;&amp;
                    (children[i].className == "analysis-body-collapsed" ||
                     children[i].className == "analysis-body")) {

                    containerBody = children[i];
                    break;
                }
            }

            return containerBody;
        },

        togglePanel: function (container) {
            var containerBody = Collapser.getContainerBody(container);
            if (containerBody == null) {
                return;
            }

            var heading = container.getElementsByTagName("H1")[0];
            var expander = heading.getElementsByClassName("expander")[0];
            if (containerBody.className == "analysis-body-collapsed") {
                containerBody.className = "analysis-body";
                expander.innerHTML = "- ";

            } else {
                containerBody.className = "analysis-body-collapsed";
                expander.innerHTML = "+ ";
            }
        },

        toggleDetails: function (element) {
            if (element.className == "scenario-details-collapsed") {
                element.className = "scenario-details";

            } else {
                element.className = "scenario-details-collapsed";
            }
        },

        initializePanels: function () {
            var elements = document.getElementsByClassName("analysis-container");
            for (var i = 0; i &lt; elements.length; i++) {
                var element = elements[i];
                var heading = element.getElementsByTagName("h1")[0];
                if (heading == null) {
                    continue;
                }

                heading.onclick = function () {
                    var container = this.parentNode;
                    Collapser.togglePanel(container);
                };
            }
        },

        initializeDetails: function() {
            var elements = document.getElementsByClassName("details-expander");
            for (var i = 0; i &lt; elements.length; i++) {
                var element = elements[i];
                var targetId = "details-" + element.id.replace("details-expand-", "");
                var targetElement = document.getElementById(targetId);
                Collapser.detailsContainers[element.id] = targetElement;
                element.onclick = function () {
                    var targetElement = Collapser.detailsContainers[this.id];
                    Collapser.toggleDetails(targetElement);
                };
            }
        },

        initializeLinks: function () {
            var links = document.getElementsByClassName("top-active-link");
            for (var i = 0; i &lt; links.length; i++) {
                var link = links[i];
                var targetId = link.getAttribute("href").substring(1);
                var targetElement = document.getElementById(targetId);
                if (targetElement.tagName.toLowerCase() == "tr") {
                    // tr, tbody, table, div.analysis-body-*, div.analysis-container
                    Collapser.topActiveBlockerDivs[targetId] =
                        targetElement.parentNode.parentNode.parentNode.parentNode;

                } else {
                    Collapser.topActiveBlockerDivs[targetId] = targetElement;
                }

                link.onclick = function () {
                    var targetId = this.getAttribute("href").substring(1);
                    var targetContainer = Collapser.topActiveBlockerDivs[targetId];
                    var container = targetContainer;
                    while ((container != null) &amp;&amp; (container.tagName == "DIV")) {
                        var containerBody = Collapser.getContainerBody(container);
                        if (containerBody == null) {
                            return;
                        }

                        if (containerBody.className == "analysis-body-collapsed") {
                            Collapser.togglePanel(container);
                        }

                        container = container.parentNode.parentNode;
                    }

                    targetContainer.scrollIntoView(true);
                };
            }
        },

        initializeCollapser: function () {
            Collapser.initializePanels();
            Collapser.initializeDetails();
            TableDecorator.decorate({
                element: ".top-blocker",
                withClass: "top-active-link"
            });

            Collapser.initializeLinks();
        },

        initialize: function () {
            if (window.addEventListener != null) {
                window.addEventListener("load", Collapser.initializeCollapser, false);

            } else if (window.attachEvent != null) {
                window.attachEvent("onload", Collapser.initializeCollapser);
            }
        }
    };
    </xsl:text>
  </xsl:template>

  <xsl:template name="jsTableDecorator">
    <xsl:text disable-output-escaping="yes">
    TableDecorator = {
        decorateTable: function (table, linkClass) {
            if (table == null) {
                return;
            }

            var rows = table.getElementsByTagName("tr");
            for (var i = 0; i &lt; rows.length; i++) {
                var row = rows[i];
                var anchor = row.getElementsByClassName("row-link")[0];
                if (anchor == null || anchor.tagName.toLowerCase() != "a") {
                    continue;
                }

                var link = anchor.getAttribute("href");
                for (var j = 0; j &lt; row.children.length; j++) {
                    var cell = row.children[j];
                    if (cell == anchor.parentNode) {
                        continue;
                    }

                    var classString = "";
                    if (linkClass != null) {
                        classString = " class=\"" + linkClass + "\"";
                    }

                    cell.innerHTML =
                        "&lt;a href=\"" + link + "\"" + classString + "&gt;" +
                        cell.innerHTML + "&lt;/a&gt;";
                }
            }
        },

        decorate: function (tableData) {
            var selection = tableData.element;
            if (selection.charAt(0) == ".") {
                var className = selection.substring(1);
                var elements = document.getElementsByClassName(className);
                for (var i = 0; i &lt; elements.length; i++) {
                    if (elements[i].tagName.toLowerCase() == "table") {
                        TableDecorator.decorateTable(elements[i], tableData.withClass);
                    }
                }

            } else if (selection.charAt(0) == "#") {
                var idName = selection.substring(1);
                var element = document.getElementById(idName);
                if (element.tagName.toLowerCase() == "table") {
                    TableDecorator.decorateTable(element, tableData.withClass);
                }
            }
        },
    };
    </xsl:text>
  </xsl:template>

  <xsl:template name="jsScrollTop">
    <xsl:text disable-output-escaping="yes">
    function initializeScrollTop() {
        var elements = document.getElementsByClassName("scroll-top-button");
        for (var i = 0; i &lt; elements.length; i++) {
            var element = elements[i];
            element.onclick = function () {
                window.scroll(0, 0);
                window.location.replace("#");
                if (typeof window.history.replaceState == "function") {
                    history.replaceState({}, "", window.location.href.slice(0, -1));
                }
            }
        }
    }
    </xsl:text>
  </xsl:template>

  <xsl:template name="javascript">
    <xsl:param name="sessions" />
    <xsl:param name="dripsBuckets" />
    <xsl:param name="energyDrains" />

    <script type="text/javascript">
      <xsl:call-template name="jsUtil" />
      <xsl:call-template name="jsDateUtil" />
      <xsl:call-template name="jsTimegraph" />
      <xsl:call-template name="jsHistogram" />
      <xsl:call-template name="jsScrollTop" />
      <xsl:call-template name="jsCollapser" />
      <xsl:call-template name="jsTableDecorator" />
      Collapser.initialize();

      <xsl:apply-templates select="$sessions" mode="jsScreenOnHistograms" />
      <xsl:apply-templates select="$dripsBuckets" mode="jsDripsBuckets" />
      <xsl:apply-templates select="$energyDrains" mode="jsEnergyDrains" />

      <xsl:text disable-output-escaping="yes">
    drainGraphLineTypes = [
        { color: "none", dotted: 0 },
        { color: "#7d7d7d", dotted: 0 },
        { color: "#2a7a2a", dotted: 0 },
        { color: "#cc7e06", dotted: 0 },
        { color: "#970d00", dotted: 0 },
        { color: "#7d7d7d", dotted: 1 },
        { color: "#2a7a2a", dotted: 1 },
        { color: "#cc7e06", dotted: 1 },
        { color: "#970d00", dotted: 1 },
    ];

    function main() {
    </xsl:text>
      <xsl:if test="$singleTraceFile = 'false'">
        <xsl:text disable-output-escaping="yes">
        TableDecorator.decorate({element: "#summary-table"});
      </xsl:text>
      </xsl:if>
      <xsl:apply-templates select="$sessions" mode="jsMainScreenOnHistograms" />
      <xsl:apply-templates select="$dripsBuckets" mode="jsMainDripsBuckets" />
      <xsl:text disable-output-escaping="yes">
        Timegraph.draw({
            element: "drain-graph",
            data: drainGraphData,
            lineTypes: drainGraphLineTypes,
            startTime: "</xsl:text><xsl:value-of select="$graphStart" /><xsl:text disable-output-escaping="yes">",
            endTime: "</xsl:text><xsl:value-of select="$reportInfo/slp:LocalScanTime" /><xsl:text disable-output-escaping="yes">"
        });

        initializeScrollTop();
    }

    if (window.addEventListener != null) {
        window.addEventListener("load", main, false);

    } else if (window.attachEvent != null) {
        window.attachEvent("onload", main);
    }
    </xsl:text>
    </script>
  </xsl:template>

  <xsl:template match="slp:Drain" mode="jsEnergyDrains">
    <xsl:text>{ </xsl:text>
    <xsl:text>x0: "</xsl:text>
    <xsl:value-of select="@LocalStartTimestamp" />
    <xsl:text>", </xsl:text>
    <xsl:text>x1: "</xsl:text>
    <xsl:value-of select="@LocalEndTimestamp" />
    <xsl:text>", </xsl:text>
    <xsl:text>y0: </xsl:text>
    <xsl:value-of select="@StartChargeCapacity div @StartFullChargeCapacity" />
    <xsl:text>, </xsl:text>
    <xsl:text>y1: </xsl:text>
    <xsl:value-of select="@EndChargeCapacity div @EndFullChargeCapacity" />
    <xsl:text>, </xsl:text>
    <xsl:text>type: </xsl:text>
    <xsl:variable name="activityType">
      <xsl:choose>
        <xsl:when test="@Activity = 'low'">2</xsl:when>
        <xsl:when test="@Activity = 'moderate'">3</xsl:when>
        <xsl:when test="@Activity = 'high'">4</xsl:when>
        <xsl:otherwise>1</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="acType">
      <xsl:choose>
        <xsl:when test="@Ac = 0">0</xsl:when>
        <xsl:otherwise>4</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:value-of select="$activityType + $acType" />
    <xsl:text>}, &#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="slp:EnergyDrains" mode="jsEnergyDrains">
    <xsl:text>
    drainGraphData = [
    </xsl:text>
    <xsl:apply-templates select="slp:Drain" mode="jsEnergyDrains" />
    <xsl:text>
    ];
    </xsl:text>
  </xsl:template>

  <xsl:template match="slp:DripsBuckets" mode="jsMainDripsBuckets">
    <xsl:text>
    Histogram.draw({
        element: "drips-histogram-</xsl:text>
    <xsl:value-of select="slp:DripBucketId/@DripBucketUniqueId"/>
    <xsl:text>",
        data: dripsBuckets_</xsl:text>
    <xsl:value-of select="position()" />
    <xsl:text>,
        rangeMax: 100
    });&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="slp:DripsBuckets" mode="jsDripsBuckets">
    <xsl:text>dripsBuckets_</xsl:text>
    <xsl:value-of select="position()" />
    <xsl:text> = [&#xa;</xsl:text>
    <xsl:apply-templates select="slp:DripsBucket" mode="jsDripsBuckets" />
    <xsl:text>
      ];
    </xsl:text>
  </xsl:template>

  <xsl:template match="slp:DripsBucket" mode="jsDripsBuckets">
    <xsl:text>{ interval : "</xsl:text>
    <xsl:value-of select="@Interval" />
    <xsl:text>", value : </xsl:text>
    <xsl:value-of select="@TotalTimePercent" />
    <xsl:text> },&#xa;</xsl:text>
    <xsl:text></xsl:text>
  </xsl:template>

  <xsl:template match="slp:ScenarioInstances" mode="jsMainScreenOnHistograms">
    <xsl:choose>
      <xsl:when test="boolean(slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance)  and boolean(slp:OsStateInstance)">
        <xsl:apply-templates select="*" mode="jsMainBrightnessDuration">
          <xsl:sort select="@OsStateId" data-type="number" order="ascending"/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="*" mode="jsMainBrightnessDuration">
          <xsl:sort select="@LocalTimestamp"/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="boolean(slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance)  and boolean(slp:OsStateInstance)">
        <xsl:apply-templates select="*" mode="jsMainLuxDuration">
          <xsl:sort select="@OsStateId" data-type="number" order="ascending"/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="*" mode="jsMainLuxDuration">
          <xsl:sort select="@LocalTimestamp"/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="slp:ScenarioInstances" mode="jsScreenOnHistograms">
    <xsl:choose>
      <xsl:when test="boolean(slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance)  and boolean(slp:OsStateInstance)">
        <xsl:apply-templates select="*" mode="jsBrightnessDuration">
          <xsl:sort select="@OsStateId" data-type="number" order="ascending"/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="*" mode="jsBrightnessDuration">
          <xsl:sort select="@LocalTimestamp"/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="boolean(slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance)  and boolean(slp:OsStateInstance)">
        <xsl:apply-templates select="*" mode="jsLuxDuration">
          <xsl:sort select="@OsStateId" data-type="number" order="ascending"/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="*" mode="jsLuxDuration">
          <xsl:sort select="@LocalTimestamp"/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance" mode="jsMainBrightnessDuration">
    <xsl:if test="slp:ScreenBrightnessHistogram">
      <xsl:text>
      Histogram.draw({
          element: "brightness-duration-</xsl:text>
      <xsl:value-of select="position()" />
      <xsl:text>",
          data: brightnessDuration_</xsl:text>
      <xsl:value-of select="position()" />
      <xsl:text>,
          rangeMax: 1
      });&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance" mode="jsBrightnessDuration">
    <xsl:if test="slp:ScreenBrightnessHistogram">
      <xsl:text>brightnessDuration_</xsl:text>
      <xsl:value-of select="position()" />
      <xsl:text> = [&#xa;</xsl:text>
      <xsl:apply-templates select="slp:ScreenBrightnessHistogram/slp:Brightness" mode="jsBrightnessDuration" />
      <xsl:text>
        ];
      </xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="slp:Brightness" mode="jsBrightnessDuration">
    <xsl:text>{ interval : "</xsl:text>
    <xsl:value-of select="@Level" />
    <xsl:text>", value : </xsl:text>
    <xsl:value-of select="@DurationSec" />
    <xsl:text> },&#xa;</xsl:text>
    <xsl:text></xsl:text>
  </xsl:template>

  <xsl:template match="slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance" mode="jsMainLuxDuration">
    <xsl:if test="slp:LuxHistogram">
      <xsl:text>
      Histogram.draw({
          element: "lux-duration-</xsl:text>
      <xsl:value-of select="position()" />
      <xsl:text>",
          data: luxDuration_</xsl:text>
      <xsl:value-of select="position()" />
      <xsl:text>,
          rangeMax: 1
      });&#xa;</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance" mode="jsLuxDuration">
    <xsl:if test="slp:LuxHistogram">
      <xsl:text>luxDuration_</xsl:text>
      <xsl:value-of select="position()" />
      <xsl:text> = [&#xa;</xsl:text>
      <xsl:apply-templates select="slp:LuxHistogram/slp:Lux" mode="jsLuxDuration" />
      <xsl:text>
        ];
      </xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="slp:Lux" mode="jsLuxDuration">
    <xsl:text>{ interval : "</xsl:text>
    <xsl:value-of select="@Level" />
    <xsl:text>", value : </xsl:text>
    <xsl:value-of select="@DurationSec" />
    <xsl:text> },&#xa;</xsl:text>
    <xsl:text></xsl:text>
  </xsl:template>

  <xsl:template match="slp:Warning">
    <div class="analysis-container warning">
      <h1>
        <span class="expander">+ </span>
        <xsl:value-of select="@Header" />
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:value-of select="@Body" disable-output-escaping="yes" />
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Warnings">
    <xsl:apply-templates select="slp:Warning" />
  </xsl:template>

  <xsl:template name="systemInformation">
    <table class="defs">
      <col />
      <xsl:if test="boolean($systemInfo)">
        <tr>
          <td class="label">
            COMPUTER NAME
          </td>
          <td>
            <xsl:value-of select="$systemInfo/slp:ComputerName" />
          </td>
        </tr>
        <tr>
          <td class="label">
            SYSTEM PRODUCT NAME
          </td>
          <td>
            <xsl:value-of select="$systemInfo/slp:SystemManufacturer" />
            <xsl:text> </xsl:text>
            <xsl:value-of select="$systemInfo/slp:SystemProductName" />
          </td>
        </tr>
        <tr>
          <td class="label">
            BIOS
          </td>
          <td>
            <xsl:value-of select="$systemInfo/slp:BIOSVersion" />
            <xsl:text> </xsl:text>
            <xsl:value-of select="$systemInfo/slp:BIOSDate" />
          </td>
        </tr>
        <tr>
          <td class="label">
            OS BUILD
          </td>
          <td>
            <xsl:value-of select="$systemInfo/slp:OSBuild" />
          </td>
        </tr>
        <tr>
          <td class="label">
            PLATFORM ROLE
          </td>
          <td>
            <xsl:value-of select="$systemInfo/slp:PlatformRole" />
          </td>
        </tr>
      </xsl:if>
      <tr>
        <td class="label">
          REPORT TIME
        </td>
        <td>
          <xsl:variable name="date" select="substring-before($localReportTime, 'T')"/>
          <xsl:variable name="time" select="translate(substring-after($localReportTime, 'T'), 'T ', '')"/>

          <span>
            <xsl:value-of select="$date"/>
            <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
            <xsl:text> </xsl:text>
          </span>
          <span>
            <xsl:value-of select="$time"/>
          </span>
        </td>
      </tr>
    </table>
  </xsl:template>

  <xsl:template name="batteryDrainGraph">
    <canvas id="drain-graph" width="864" height="400">&#160;</canvas>

    <table id="legend">
      <colgroup>
        <col />
        <col />
      </colgroup>
      <caption>Legend</caption>
      <thead>
        <th>GRAPH LINE</th>
        <th>DESCRIPTION</th>
      </thead>
      <tbody>
        <tr>
          <td>
            <span class="graphline-dotted">Dotted</span>
          </td>
          <td colspan="2">AC power </td>
        </tr>
        <tr>
          <td>
            <span class="graphline-solid">Solid</span>
          </td>
          <td colspan="2">Battery power</td>
        </tr>
        <tr>
          <td>
            <span class="graphline-none">No line</span>
          </td>
          <td colspan="2">System powered off</td>
        </tr>
        <tr>
          <td colspan="3" class="spanner"></td>
        </tr>
        <tr>
          <td>
            <span class="graphline-neutral">Grey</span>
          </td>
          <td colspan="2">Active Scenario</td>
        </tr>
        <tr>
          <td>
            <span class="graphline-low">Green</span>
          </td>
          <td>Low System Activity</td>
        </tr>
        <tr>
          <td>
            <span class="graphline-moderate">Orange</span>
          </td>
          <td>Moderate System Activity</td>
        </tr>
        <tr>
          <td>
            <span class="graphline-high">Red</span>
          </td>
          <td>High System Activity</td>
        </tr>
        <tr>
          <td>
            <span class="graphline-nonclean">Violet</span>
          </td>
          <td>Abnormal Shutdown</td>
        </tr>
      </tbody>
    </table>
  </xsl:template>

  <xsl:template match="slp:ScenarioInstances" mode="summaryTable">
    <h2>
      Filter Option.
    </h2>
    <h4>Session Length:</h4>
    <input type="radio" name="session1" id="is_all_time" value="Alltime" onchange="js:durationValueChanged()" checked=""/>
    <label>All</label>
    <xsl:text> </xsl:text>
    <input type="radio" name="session1" id="is_10_session" value="10:00" onchange="js:durationValueChanged()"/>
    <label>> 10 min </label>
    <h4>States:</h4>
    <input type="radio" name="session" id="is_all_session" value="All" onchange="js:osStateValueChanged()" checked=""/>
    <label>All</label>
    <xsl:text> </xsl:text>
    <input type="radio" name="session" id="is_active_session" value="Active" onchange="js:osStateValueChanged()"/>
    <label>Active</label>
    <xsl:text> </xsl:text>
    <input type="radio" name="session" id="is_screenoff_session" value="ScreenOff" onchange="js:osStateValueChanged()" />
    <label>Screen Off </label>
    <input type="radio" name="session" id="is_sleep_session" value="Standby" onchange="js:osStateValueChanged()" />
    <label>Sleep</label>
    <xsl:text> </xsl:text>
    <input type="radio" name="session" id="is_hib_session" value="Hibernate" onchange="js:osStateValueChanged()"/>
    <label>Hibernate</label>
    <xsl:text> </xsl:text>
    <input type="radio" name="session" id="is_shutdown_session" value="Shutdown" onchange="js:osStateValueChanged()"/>
    <label>Shutdown</label>
    <xsl:text> </xsl:text>
    <input type="radio" name="session" id="is_bug_session" value="Bug Check" onchange="js:osStateValueChanged()"/>
    <label>Bug Check</label>
    <xsl:text> </xsl:text>

    <table id="summary-table">
        <colgroup>
        <col style="width: 2em" />
        <col style="width: 11em;" />
        <col style="width: 5em;" />
        <col style="width: 10em;" />
        <col class="width: 13em;" />
        <col class="width: 13em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
        <!-- Hack to make the colgroups play well with both when we do display
             the HW DRIPS cell and when we do not and the DRIPS cell spans
             two columns -->
        <col style="width: 1em;" />
      </colgroup>
      <thead>
        <tr>
          <th></th>
          <th>START TIME</th>
          <th>DURATION</th>
          <th>STATE</th>
          <th colspan="2">ENERGY CHANGE</th>
          <th colspan="2">CHANGE RATE</th>
          <th colspan="2">% LOW POWER STATE TIME</th>
          <th>% CAPACITY REMAINING AT START</th>
        </tr>
      </thead>

      <xsl:choose>
        <xsl:when test="boolean(slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance)  and boolean(slp:OsStateInstance)">
          <xsl:apply-templates select="*" mode="summaryTable">
            <xsl:sort select="@OsStateId" data-type="number" order="ascending"/>
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="*" mode="summaryTable">
            <xsl:sort select="@LocalTimestamp"/>
          </xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>

      <!-- No data. Show one line of dashes -->
      <xsl:choose>
        <xsl:when test ="not(boolean(slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance))" >
          <tr>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
            <td class="nullValue">-</td>
          </tr>
        </xsl:when>
      </xsl:choose>
    </table>
  </xsl:template>

  <!-- Outputs the "Battery usage" table contents -->
  <xsl:template match="slp:ScenarioInstance|slp:OsStateInstance|slp:RecentUsageInstance" mode="summaryTable">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <td class="centered">
        <a>
          <xsl:attribute name="href">
            <xsl:text>#connected-standby-session-</xsl:text>
            <xsl:value-of select="position()" />
          </xsl:attribute>
          <xsl:attribute name="class">
            <xsl:text>row-link</xsl:text>
          </xsl:attribute>
          <xsl:value-of select="position()" />
        </a>
      </td>
      <td class="dateTime">
        <xsl:call-template name="formatDateTime">
          <xsl:with-param name="dateTime" select="@LocalTimestamp" />
          <xsl:with-param name="showDate" select="js:parseDate(string(@LocalTimestamp)) != js:parseDate(string(preceding-sibling::*[1]/@LocalTimestamp))" />
        </xsl:call-template>
      </td>

      <!-- Duration -->
      <td class="hms">
        <xsl:choose>
          <xsl:when test="boolean(@Duration)">
            <xsl:value-of select="js:formatDurationMs(string(@Duration div 10000))" />
          </xsl:when>
          <xsl:otherwise>
            <xsl-text>-</xsl-text>
          </xsl:otherwise>
        </xsl:choose>
      </td>

      <!-- State -->
      <td class="state">
        <xsl:value-of select="@Type" />
      </td>

      <!-- Energy change -->
      <xsl:call-template name="mWhCell">
        <xsl:with-param name="batteryDrain" select="@Discharge" />
        <xsl:with-param name="batteryCapacity" select="@FullChargeCapacity" />
        <xsl:with-param name="batteryCountChanged" select="@BatteryCountChanged" />
      </xsl:call-template>

      <!-- Change rate -->
      <xsl:call-template name="mWCell">
        <xsl:with-param name="energyDrain" select="@EnergyDrain" />
        <xsl:with-param name="batteryCountChanged" select="@BatteryCountChanged" />
      </xsl:call-template>

      <!-- Charge/Drain -->
      <td class="chargeOrDrain">
        <xsl:choose>
          <xsl:when test="boolean(@Ac)">
            <xsl:choose>
              <xsl:when test="boolean(@SpmScenarioStopReason)">
                <xsl:value-of select="js:createChargeDrainString(string(@Ac), string(@SpmScenarioStopReason))" />
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="js:createChargeDrainString(string(@Ac), '17')" />
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl-text>-</xsl-text>
          </xsl:otherwise>
        </xsl:choose>
      </td>

      <!-- % Low Power State Time -->
      <xsl:choose>
        <xsl:when test="boolean(@HwLowPowerStateTime) and (@LowPowerStateTime != 0)">
          <td class="percentLowPowerStateTime">
            SW: <xsl:value-of select="round(100 * @LowPowerStateTime div @Duration)" />%
          </td>
          <td class="percentLowPowerStateTime">
            HW: <xsl:value-of select="round(100 * @HwLowPowerStateTime div @Duration)" />%
          </td>
        </xsl:when>
        <xsl:when test="boolean(@HwLowPowerStateTime) and (@LowPowerStateTime = 0)">
          <td class="percentLowPowerStateTime">
            SW: <xsl:value-of select="round(100 * @LowPowerStateTime div @Duration)" />%
          </td>
          <td class="percentLowPowerStateTime">
            HW: -
          </td>
        </xsl:when>
        <xsl:otherwise>
          <td class="percentLowPowerStateTime" colspan="2">
            <xsl:choose>
              <xsl:when test="boolean(@LowPowerStateTime)">
                SW: <xsl:value-of select="round(100 * @LowPowerStateTime div @Duration)" />%
              </xsl:when>
              <xsl:otherwise>
                <xsl-text>-</xsl-text>
              </xsl:otherwise>
            </xsl:choose>
          </td>
        </xsl:otherwise>
      </xsl:choose>

      <!-- Start Capacity remaining -->
      <xsl:call-template name="percentCell">
        <xsl:with-param name="remainingCapacity" select="@EntryRemainingCapacity" />
        <xsl:with-param name="fullCapacity" select="@EntryFullCapacity" />
        <xsl:with-param name="batteryCountChanged" select="@BatteryCountChanged" />
      </xsl:call-template>

      <!-- Hack to make the colgroups play well with both when we do display
           the HW DRIPS cell and when we do not and the DRIPS cell spans
           two columns -->
      <td class="blank"></td>
    </tr>

  </xsl:template>

  <xsl:template match="slp:ScenarioInstances" mode="analysisResults">
    <xsl:choose>
      <xsl:when test ="boolean(slp:OsStateInstance)" >
        <xsl:apply-templates select="*" mode="analysisResults">
          <xsl:sort select="@OsStateId" data-type="number" order="ascending"/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="*" mode="analysisResults">
          <xsl:sort select="@LocalTimestamp"/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="slp:OsStateInstance" mode="analysisResults">
    <a>
      <xsl:attribute name="name">
        <xsl:text>connected-standby-session-</xsl:text>
        <xsl:value-of select="position()" />
      </xsl:attribute>
    </a>
    <div class="scroll-top-button">Top</div>
    <h3>
      System Power State:  <xsl:value-of select="@Type" />
    </h3>
    <table class="session-summary">
      <colgroup>
        <col style="width: 2em" />
        <col style="width: 11em;" />
        <col style="width: 5em;" />
        <col style="width: 10em" />
        <col style="width: 16em" />
        <col style="width: 16em" />
        <col style="width: 6em;" />
      </colgroup>
      <thead>
        <tr>
          <th></th>
          <th>START TIME</th>
          <th>DURATION</th>
          <th>STATE</th>
          <th>ENTRY REASON</th>
          <th>EXIT REASON</th>
          <th>% CAPACITY REMAINING AT START</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <xsl:attribute name="class">
            <xsl:text>row-</xsl:text>
            <xsl:value-of select="@ActivityLevel" />
          </xsl:attribute>
          <td class="centered">
            <xsl:value-of select="position()" />
          </td>

          <!-- Start Time -->
          <td class="dateTime">
            <xsl:call-template name="formatDateTime">
              <xsl:with-param name="dateTime" select="@LocalTimestamp" />
            </xsl:call-template>
          </td>

          <!-- Duration -->
          <td class="hms">
            <xsl:choose>
              <xsl:when test="boolean(@Duration)">
                <xsl:value-of select="js:formatDurationMs(string(@Duration div 10000))" />
              </xsl:when>
              <xsl:otherwise>
                <xsl-text>-</xsl-text>
              </xsl:otherwise>
            </xsl:choose>
          </td>

          <td class="OsState" align="center">
            <xsl:value-of select="@Type" />
          </td>

          <td class="EntryReason" align="center">
            <xsl:value-of select="@EntryReason" />
          </td>

          <td class="ExitReason" align="center">
            <xsl:value-of select="@ExitReason" />
          </td>

          <!-- Start Capacity remaining -->
            <xsl:call-template name="percentCell">
              <xsl:with-param name="remainingCapacity" select="@EntryRemainingCapacity" />
              <xsl:with-param name="fullCapacity" select="@EntryFullCapacity" />
              <xsl:with-param name="batteryCountChanged" select="@BatteryCountChanged" />
            </xsl:call-template>

        </tr>
      </tbody>
    </table>
    <xsl:apply-templates select="slp:CustomData" mode="analysisTopLevel" />
  </xsl:template>

  <xsl:template match="slp:CustomData" mode="analysisTopLevel">
    <xsl:apply-templates select="slp:CustomDataHeading" />
    <xsl:apply-templates select="slp:OSStateCustomData" />
  </xsl:template>

  <xsl:template match="slp:CustomDataHeading">
    <h4>
      <xsl:value-of select="@Head"/>
    </h4>
  </xsl:template>

  <xsl:template match="slp:OSStateCustomData">
    <h4>OS State Data</h4>
    <div class="explanation">
      Data obtained from the Event Viewer Logger.
    </div>
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <h1>
        <span class="expander">+ </span>Detailed OS State Data
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:choose>
          <xsl:when test="count(slp:OSStateRecord) = 0">
            <div class="analysis-empty">No data obtained.</div>
          </xsl:when>
          <xsl:otherwise>
            <table class="pdc-phases">
              <thead>
                <th>Name</th>
                <th>Value</th>
              </thead>
              <tbody>
                <xsl:apply-templates select="slp:OSStateRecord">
                </xsl:apply-templates>
              </tbody>
            </table>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:OSStateRecord">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-info</xsl:text>
      </xsl:attribute>
      <td class="center">
        <xsl:value-of select="@Name" />
      </td>
      <td class="center">
        <xsl:value-of select="@Value" />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:ScenarioInstance" mode="analysisResults">
    <xsl-text></xsl-text>
    <a>
      <xsl:attribute name="name">
        <xsl:text>connected-standby-session-</xsl:text>
        <xsl:value-of select="position()" />
      </xsl:attribute>
    </a>
    <div class="scroll-top-button">Top</div>
    <h3>
      System Power State:  <xsl:value-of select="@Type" />
    </h3>
    <table class="session-summary">
      <colgroup>
        <col style="width: 2em" />
        <col style="width: 11em;" />
        <col style="width: 5em;" />
        <col style="width: 10em;" />
        <col class="width: 13em;" />
        <col class="width: 13em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
      </colgroup>
      <thead>
        <tr>
          <th></th>
          <th>START TIME</th>
          <th>DURATION</th>
          <th>STATE</th>
          <th colspan="2">ENERGY CHANGE</th>
          <th colspan="2">CHANGE RATE</th>
          <th colspan="2">% LOW POWER STATE TIME</th>
          <th>% CAPACITY REMAINING AT START</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <xsl:attribute name="class">
            <xsl:text>row-</xsl:text>
            <xsl:value-of select="@ActivityLevel" />
          </xsl:attribute>
          <td class="centered">
            <xsl:value-of select="position()" />
          </td>
          <td class="dateTime">
            <xsl:call-template name="formatDateTime">
              <xsl:with-param name="dateTime" select="@LocalTimestamp" />
            </xsl:call-template>
          </td>
          <td class="hms">
            <xsl:value-of select="js:formatDurationMs(string(@Duration div 10000))" />
          </td>

          <!-- State -->
          <td class="state">
            <xsl:value-of select="@Type" />
          </td>

          <!-- Energy change -->
          <xsl:call-template name="mWhCell">
            <xsl:with-param name="batteryDrain" select="@Discharge" />
            <xsl:with-param name="batteryCapacity" select="@FullChargeCapacity" />
            <xsl:with-param name="batteryCountChanged" select="@BatteryCountChanged" />
          </xsl:call-template>

          <!-- Change rate -->
          <xsl:call-template name="mWCell">
            <xsl:with-param name="energyDrain" select="@EnergyDrain" />
            <xsl:with-param name="batteryCountChanged" select="@BatteryCountChanged" />
          </xsl:call-template>

          <!-- Charge/Drain -->
          <td class="chargeOrDrain">
            <xsl:value-of select="js:createChargeDrainString(string(@Ac), string(@SpmScenarioStopReason))" />
          </td>

          <!-- % Low Power State Time -->
          <xsl:choose>
            <xsl:when test="@HwLowPowerStateTime or @LowPowerStateTime">
              <xsl:choose>
                <xsl:when test="boolean(@HwLowPowerStateTime) and (@LowPowerStateTime != 0)">
                  <td class="percentLowPowerStateTime">
                    SW: <xsl:value-of select="round(100 * @LowPowerStateTime div @Duration)" />%
                  </td>
                  <td class="percentLowPowerStateTime">
                    HW: <xsl:value-of select="round(100 * @HwLowPowerStateTime div @Duration)" />%
                  </td>
                </xsl:when>
                <xsl:when test="boolean(@HwLowPowerStateTime) and (@LowPowerStateTime = 0)">
                  <td class="percentLowPowerStateTime">
                    SW: <xsl:value-of select="round(100 * @LowPowerStateTime div @Duration)" />%
                  </td>
                  <td class="percentLowPowerStateTime">
                    HW: -
                  </td>
                </xsl:when>
                <xsl:otherwise>
                  <td class="percentLowPowerStateTime" colspan="2">
                    SW: <xsl:value-of select="round(100 * @LowPowerStateTime div @Duration)" />%
                  </td>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <td class="percentLowPowerStateTime" colspan="2">-</td>
            </xsl:otherwise>
          </xsl:choose>

          <!-- Start Capacity remaining -->
          <xsl:call-template name="percentCell">
            <xsl:with-param name="remainingCapacity" select="@EntryRemainingCapacity" />
            <xsl:with-param name="fullCapacity" select="@EntryFullCapacity" />
            <xsl:with-param name="batteryCountChanged" select="@BatteryCountChanged" />
          </xsl:call-template>

          <!-- More information expander -->
          <td>
            <xsl:attribute name="class">
              <xsl:text>details-expander</xsl:text>
            </xsl:attribute>
            <xsl:attribute name="id">
              <xsl:text>details-expand-</xsl:text>
              <xsl:value-of select="position()" />
            </xsl:attribute>
            &#8942;
          </td>
        </tr>
      </tbody>
    </table>
    <div>
      <xsl:attribute name="class">
        <xsl:text>scenario-details-collapsed</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="id">
        <xsl:text>details-</xsl:text>
        <xsl:value-of select="position()" />
      </xsl:attribute>
      <table class="defs">
        <xsl:choose>
          <xsl:when test="@EntryRemainingCapacity">
            <tr>
              <td class="label">REMAINING CHARGE CAPACITY AT ENTRY</td>
              <td>
                <xsl:value-of select="@EntryRemainingCapacity" /> mWh
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="@EntryFullCapacity">
            <tr>
              <td class="label">FULL CHARGE CAPACITY AT ENTRY</td>
              <td>
                <xsl:value-of select="@EntryFullCapacity" /> mWh
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="@ExitRemainingCapacity">
            <tr>
              <td class="label">REMAINING CHARGE CAPACITY AT EXIT</td>
              <td>
                <xsl:value-of select="@ExitRemainingCapacity" /> mWh
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="@ExitFullCapacity">
            <tr>
              <td class="label">FULL CHARGE CAPACITY AT EXIT</td>
              <td>
                <xsl:value-of select="@ExitFullCapacity" /> mWh
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="@DisconnectedStandby">
            <tr>
              <td class="label">NETWORKING IN STANDBY</td>
              <td>
                <xsl:choose>
                  <xsl:when test="@DisconnectedStandby = '0'">Connected</xsl:when>
                  <xsl:otherwise>Disconnected</xsl:otherwise>
                </xsl:choose>
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="@EnergySaverPolicy">
            <tr>
              <td class="label">ENERGY SAVER IN STANDBY</td>
              <td>
                <xsl:choose>
                  <xsl:when test="@EnergySaverPolicy = '0'">OFF</xsl:when>
                  <xsl:otherwise>ON</xsl:otherwise>
                </xsl:choose>
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="@IsDebuggerEnabled">
            <tr>
              <td class="label">DEBUG ENABLED</td>
              <td>
                <xsl:choose>
                  <xsl:when test="@IsDebuggerEnabled = '0'">NO</xsl:when>
                  <xsl:otherwise>YES</xsl:otherwise>
                </xsl:choose>
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="@IsLockConsoleTimeoutActive">
            <tr>
              <td class="label">LOCK CONSOLE TIMEOUT ACTIVE</td>
              <td>
                <xsl:choose>
                  <xsl:when test="@IsLockConsoleTimeoutActive = '0'">NO</xsl:when>
                  <xsl:otherwise>YES</xsl:otherwise>
                </xsl:choose>
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="@SystemGpuAdapterCount">
            <tr>
              <td class="label">SYSTEM GPU ADAPTER COUNT</td>
              <td>
                <xsl:value-of select="@SystemGpuAdapterCount" />
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="@PreVetoCount">
            <tr>
              <td class="label">PEP PRE-VETO COUNT</td>
              <td>
                <xsl:value-of select="@PreVetoCount" />
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <tr>
          <td class="label">ENTER REASON</td>
          <td>
            <xsl:choose>
              <xsl:when test="@CsEnterReasonPdcSignalReasonDetails">
                <xsl:value-of select="concat(@CsEnterReason, ' : ', @CsEnterReasonPdcSignalReasonDetails)" />
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="@CsEnterReason" />
              </xsl:otherwise>
            </xsl:choose>
          </td>
        </tr>
        <xsl:if test="@CsEnterReasonPdcSignalReasonDetails and (@CsEnterReasonPdcSignalUnknown != 0)">
          <tr>
            <td class="label">ENTER PDC SIGNAL CLASS</td>
            <td>
              <xsl:value-of select="@CsEnterReasonPdcSignalClassGuid" />
            </td>
          </tr>
          <tr>
            <td class="label">ENTER PDC SIGNAL PROVIDER</td>
            <td>
              <xsl:value-of select="@CsEnterReasonPdcSignalProviderGuid" />
            </td>
          </tr>
        </xsl:if>
        <tr>
          <td class="label">EXIT REASON</td>
          <td>
            <xsl:choose>
              <xsl:when test="@CsExitReasonPdcSignalReasonDetails">
                <xsl:value-of select="concat(@CsExitReason, ' : ', @CsExitReasonPdcSignalReasonDetails)" />
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="@CsExitReason" />
              </xsl:otherwise>
            </xsl:choose>
          </td>
        </tr>
        <xsl:if test="@CsExitReasonPdcSignalReasonDetails and (@CsExitReasonPdcSignalUnknown != 0)">
          <tr>
            <td class="label">EXIT PDC SIGNAL CLASS</td>
            <td>
              <xsl:value-of select="@CsExitReasonPdcSignalClassGuid" />
            </td>
          </tr>
          <tr>
            <td class="label">EXIT PDC SIGNAL PROVIDER</td>
            <td>
              <xsl:value-of select="@CsExitReasonPdcSignalProviderGuid" />
            </td>
          </tr>
        </xsl:if>
        <xsl:choose>
          <xsl:when test="@DirectedDripsTransitionCount">
            <tr>
              <td class="label">DIRECTED DRIPS TRANSITIONS</td>
              <td>
                <xsl:value-of select="@DirectedDripsTransitionCount" />
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
        <xsl:choose>
          <xsl:when test="@CsExitLatencyInMs">
            <tr>
              <td class="label">EXIT LATENCY [ms]</td>
              <td>
                <xsl:value-of select="@CsExitLatencyInMs" />
              </td>
            </tr>
          </xsl:when>
        </xsl:choose>
      </table>
      <xsl:choose>
          <xsl:when test="@CsExitLatencyInMs">
            <table>
              <tr>
                <th align="left">CS EXIT LATENCY PHASE BREAKDOWN [ms]</th>
              </tr>
              <tr>
                <td class="label"  colspan="16">CS EXIT TIME SPENT IN RESILIENCY</td>
                <td>
                  <xsl:value-of select="@CsExitTimeSpentInResiliency" />
                </td>
              </tr>
              <tr>
                <td class="label"  colspan="16">CS EXIT TIME SPENT IN RESILIENCY NOTIFICATION</td>
                <td>
                  <xsl:value-of select="@CsExitTimeSpentInResiliencyNotif" />
                </td>
              </tr>
              <tr>
                <td class="label" colspan="16">CS EXIT TIME SPENT IN LOW POWER EPOCH</td>
                <td>
                  <xsl:value-of select="@CsExitTimeSpentInLowPower" />
                </td>
              </tr>
              <tr>
                <td class="label"  colspan="16">CS EXIT TIME SPENT IN DAM</td>
                <td>
                  <xsl:value-of select="@CsExitTimeSpentInDam" />
                </td>
              </tr>
              <tr>
                <td class="label"  colspan="16">CS EXIT TIME SPENT IN MAINTENANCE</td>
                <td>
                  <xsl:value-of select="@CsExitTimeSpentInMaintenance" />
                </td>
              </tr>
              <tr>
                <td class="label"  colspan="16">CS EXIT TIME SPENT IN PLM</td>
                <td>
                  <xsl:value-of select="@CsExitTimeSpentInPlm" />
                </td>
              </tr>
              <tr>
                <td class="label"  colspan="16">CS EXIT TIME SPENT IN SHELL</td>
                <td>
                  <xsl:value-of select="@CsExitTimeSpentInPresence" />
                </td>
              </tr>
              <tr>
                <td class="label"  colspan="16">CS EXIT TIME SPENT IN CONNECTION</td>
                <td>
                  <xsl:value-of select="@CsExitTimeSpentInConnection" />
                </td>
              </tr>
              <tr>
                <td class="label"  colspan="16">CS EXIT TIME SPENT TURNING SCREEN ON</td>
                <td>
                  <xsl:value-of select="@CsExitTimeSpentInScreenOn" />
                </td>
              </tr>
              <tr>
                <td class="labeldetails"  colspan="16">GRAPHICS DEVICE INTERFACE (GDI)</td>
                <td>
                  <xsl:value-of select="@GdiOnTime" />
                </td>
              </tr>
              <tr>
                <td class="labeldetails"  colspan="16">DESKTOP WINDOW MANAGER (DWM)</td>
                <td>
                  <xsl:value-of select="@DwmSyncFlushTime" />
                </td>
              </tr>
              <tr>
                <td class="labeldetails"  colspan="16">MONITOR POWER ON</td>
                <td>
                  <xsl:value-of select="@MonitorPowerOnTime" />
                </td>
              </tr>
              <tr>
                <td class="labeldetails"  colspan="16">REQUEST PROCESSING</td>
                <td>
                  <xsl:value-of select="@ScreenOnOverhead" />
                </td>
              </tr>
            </table>
          </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="@Type = 'Screen Off'">
          <table>
            <tr>
              <th align="left">SESSION TIMEOUT VALUES [seconds]</th>
            </tr>
            <tr>
              <td class="label" colspan="16">TURN OFF DISPLAY AFTER TIMEOUT</td>
              <td>
                <xsl:value-of select="@VideoTimeoutInSec" />
              </td>
            </tr>
            <tr>
              <td class="label" colspan="16">CONSOLE LOCK DISPLAY OFF TIMEOUT</td>
              <td>
                <xsl:value-of select="@LockConsoleTimeoutInSec" />
              </td>
            </tr>
            <tr>
              <td class="label" colspan="16">SLEEP AFTER TIMEOUT</td>
              <td>
                <xsl:value-of select="@StandbyTimeoutInSec" />
              </td>
            </tr>
          </table>
        </xsl:when>
      </xsl:choose>
      <table>
        <tr>
          <th align="left">HIBERNATE SETTINGS</th>
        </tr>
        <tr>
          <td class="label" colspan="16">HIBERNATE ENABLED</td>
          <td>
            <xsl:choose>
              <xsl:when test="@IsHibernateEnabled = '0'">NO</xsl:when>
              <xsl:otherwise>YES</xsl:otherwise>
            </xsl:choose>
          </td>
        </tr>
        <xsl:choose>
          <xsl:when test="@IsHibernateEnabled = '0'"></xsl:when>
          <xsl:otherwise>
            <tr>
              <td class="label" colspan="16">HIBERNATE TIMEOUT</td>
              <td>
                <xsl:value-of select="@HibernateTimeoutInSec" />
              </td>
            </tr>
            <tr>
              <td class="label" colspan="16">HIBERNATE BUDGET [percentage of battery]</td>
              <td>
                <xsl:value-of select="@HibernateBudgetPercentage" />
              </td>
            </tr>
          </xsl:otherwise>
        </xsl:choose>
      </table>
    </div>

    <xsl:if test="count(slp:DripsBuckets)">
      <h4>DRIPS Histogram</h4>
      <div class="explanation">Percent of time spent in DRIPS bucketed by time interval length</div>
      <canvas>
        <xsl:attribute name="id">
          <xsl:text>drips-histogram-</xsl:text>
          <xsl:value-of select="slp:DripsBuckets/slp:DripBucketId/@DripBucketUniqueId"/>
        </xsl:attribute>
        <xsl:attribute name="width">
          <xsl:text>864</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="height">
          <xsl:text>300</xsl:text>
        </xsl:attribute>
        <xsl:text> </xsl:text>
      </canvas>
    </xsl:if>

    <xsl:apply-templates select="slp:DripsWakeSources" />
    <xsl:apply-templates select="slp:TopBlockers" mode="analysisTopLevel" />
    <xsl:apply-templates select="slp:Activators" mode="analysisTopLevel" />
    <xsl:apply-templates select="slp:Processors" mode="analysisTopLevel" />
    <xsl:apply-templates select="slp:Devices" mode="analysisTopLevel" />
    <xsl:apply-templates select="slp:Phases" mode="analysisTopLevel" />
    <xsl:apply-templates select="slp:PepPreVetoes" mode="analysisTopLevel" />
    <xsl:apply-templates select="slp:SocSubsystems" mode="analysisTopLevel" />
    <xsl:apply-templates select="slp:Blockers" mode="analysisTopLevel" />
    <xsl:apply-templates select="slp:SrumData" mode="analysisTopLevel" />
  </xsl:template>

  <xsl:template match="slp:TopBlockers" mode="analysisTopLevel">
    <h4>Top Offenders</h4>
    <div class="explanation">
      Top 5 offenders, ranked by active time
    </div>

    <table style="margin-bottom: 20px" class="top-blocker">
      <colgroup>
        <col />
        <col />
        <col />
        <col />
      </colgroup>
      <thead>
        <tr>
          <th>
            NAME
          </th>
          <th>
            TYPE
          </th>
          <th>
            % ACTIVE TIME
          </th>
          <th>
            ACTIVE TIME
          </th>
        </tr>
      </thead>
      <tbody>
        <xsl:apply-templates select="slp:TopBlocker" />
      </tbody>
    </table>
  </xsl:template>

  <xsl:template name="activeTime">
    <xsl:param name="time" />
    <xsl:choose>
      <xsl:when test="$time = 'invalid'">n/a</xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="js:formatDurationMs(string($time div 10000))" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="activeTimePercent">
    <xsl:param name="timePercent" />
    <xsl:choose>
      <xsl:when test="$timePercent = 'invalid'">n/a</xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$timePercent" />%
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="slp:TopBlocker">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>

      <td>
        <a>
          <xsl:attribute name="href">
            <xsl:text>#offender-</xsl:text>
            <xsl:value-of select="@Id" />
          </xsl:attribute>
          <xsl:attribute name="class">
            <xsl:text>top-active-link row-link</xsl:text>
          </xsl:attribute>
          <xsl:choose>
            <xsl:when test="@Name = ''">Unknown</xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="@Name" />
            </xsl:otherwise>
          </xsl:choose>
        </a>
      </td>
      <td class="center">
        <xsl:value-of select="@Type" />
      </td>
      <td class="percent">
        <xsl:call-template name="activeTimePercent">
          <xsl:with-param name="timePercent" select="@SegmentActiveTimePercent" />
        </xsl:call-template>
      </td>
      <td class="center">
        <xsl:call-template name="activeTime">
          <xsl:with-param name="time" select="@ActiveTime" />
        </xsl:call-template>
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:Errors" mode="blockerErrors">
    <div class="analysis-container error">
      <h1>
        <span class="expander">+ </span>
        <xsl:value-of select="@Header" />
      </h1>
      <div class="analysis-body-collapsed">
        <ul>
          <xsl:for-each select=".">
            <li>
              <xsl:value-of select="slp:Error" />
            </li>
          </xsl:for-each>
        </ul>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Processors" mode="analysisTopLevel">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <h1>
        <span class="expander">+ </span>Processors
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:apply-templates select="slp:Errors" mode="blockerErrors" />
        <xsl:choose>
          <xsl:when test="count(slp:Processor)">
            <xsl:apply-templates select="slp:Processor" />
          </xsl:when>
          <xsl:otherwise>
            <div class="analysis-empty">No processor activity reported.</div>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Processor">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <xsl:if test="@Id">
        <xsl:attribute name="id">
          <xsl:text>offender-</xsl:text>
          <xsl:value-of select="@Id" />
        </xsl:attribute>
      </xsl:if>
      <h1>
        <span class="expander">+ </span>
        <xsl:value-of select="@Name" />
      </h1>
      <div class="analysis-body-collapsed">
        <table class="defs">
          <tr>
            <td class="label">% ACTIVE TIME</td>
            <td class="label">ACTIVE TIME</td>
          </tr>
          <tr>
            <td class="percent">
              <xsl:call-template name="activeTimePercent">
                <xsl:with-param name="timePercent" select="@SegmentActiveTimePercent" />
              </xsl:call-template>
            </td>
            <td class="center">
              <xsl:call-template name="activeTime">
                <xsl:with-param name="time" select="@ActiveTime" />
              </xsl:call-template>
            </td>
          </tr>
        </table>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Activators" mode="analysisTopLevel">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <h1>
        <span class="expander">+ </span>Activators
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:apply-templates select="slp:Errors" mode="blockerErrors" />
        <xsl:choose>
          <xsl:when test="count(slp:Activator)">
            <xsl:apply-templates select="slp:Activator" />
          </xsl:when>
          <xsl:otherwise>
            <div class="analysis-empty">No activator activity reported.</div>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Activator">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <xsl:if test="@Id">
        <xsl:attribute name="id">
          <xsl:text>offender-</xsl:text>
          <xsl:value-of select="@Id" />
        </xsl:attribute>
      </xsl:if>
      <h1>
        <span class="expander">+ </span>
        <xsl:value-of select="@Name" />
      </h1>
      <div class="analysis-body-collapsed">
        <table class="defs">
          <tr>
            <td class="label">% ACTIVE TIME</td>
            <td class="label">ACTIVE TIME</td>
          </tr>
          <tr>
            <td class="percent">
              <xsl:call-template name="activeTimePercent">
                <xsl:with-param name="timePercent" select="@SegmentActiveTimePercent" />
              </xsl:call-template>
            </td>
            <td class="center">
              <xsl:call-template name="activeTime">
                <xsl:with-param name="time" select="@ActiveTime" />
              </xsl:call-template>
            </td>
          </tr>
        </table>
        <xsl:apply-templates select="slp:CustomData" />
        <xsl:apply-templates select="slp:Blockers" />
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Phase">
    <tr>
      <xsl:if test="boolean(@Id)">
        <xsl:attribute name="id">
          <xsl:text>offender-</xsl:text>
          <xsl:value-of select="@Id" />
        </xsl:attribute>
      </xsl:if>
      <xsl:attribute name="class">
        <xsl:text>row-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <td>
        <xsl:value-of select="@Name" />
      </td>
      <td class="percent">
        <xsl:call-template name="activeTimePercent">
          <xsl:with-param name="timePercent" select="@SegmentActiveTimePercent" />
        </xsl:call-template>
      </td>
      <td class="center">
        <xsl:call-template name="activeTime">
          <xsl:with-param name="time" select="@ActiveTime" />
        </xsl:call-template>
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:Phases" mode="analysisTopLevel">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <h1>
        <span class="expander">+ </span>PDC Phases
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:apply-templates select="slp:Errors" mode="blockerErrors" />
        <table class="pdc-phases">
          <thead>
            <th>PHASE</th>
            <th>% TIME</th>
            <th>TIME</th>
          </thead>
          <tbody>
            <xsl:apply-templates select="slp:Phase" />
          </tbody>
        </table>
        <xsl:choose>
          <xsl:when test="count(slp:PhaseBlockers)">
            <xsl:apply-templates select="slp:PhaseBlockers" />
          </xsl:when>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:PhaseBlockers">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <h1>
        <span class="expander">+ </span>
        <xsl:value-of select="@Name"/>
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:apply-templates select="slp:Blocker" />
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Devices" mode="analysisTopLevel">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <h1>
        <span class="expander">+ </span>Fx Devices
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:apply-templates select="slp:Errors" mode="blockerErrors" />
        <xsl:choose>
          <xsl:when test="count(slp:Device)">
            <xsl:apply-templates select="slp:Device" />
          </xsl:when>
          <xsl:otherwise>
            <div class="analysis-empty">No device activity reported.</div>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Device">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <xsl:if test="@Id">
        <xsl:attribute name="id">
          <xsl:text>offender-</xsl:text>
          <xsl:value-of select="@Id" />
        </xsl:attribute>
      </xsl:if>
      <h1>
        <span class="expander">+ </span>
        <xsl:value-of select="@Name" />
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:if test="@ActiveTime and @SegmentActiveTimePercent and @ActiveTime != 0">
          <table class="defs">
            <tr>
              <td class="label">% ACTIVE TIME</td>
              <td class="label">ACTIVE TIME</td>
            </tr>
            <tr>
              <td class="percent">
                <xsl:call-template name="activeTimePercent">
                  <xsl:with-param name="timePercent" select="@SegmentActiveTimePercent" />
                </xsl:call-template>
              </td>
              <td class="center">
                <xsl:call-template name="activeTime">
                  <xsl:with-param name="time" select="@ActiveTime" />
                </xsl:call-template>
              </td>
            </tr>
          </table>
        </xsl:if>
        <xsl:apply-templates select="slp:Blockers" />
        <table class="device-components">
          <xsl:choose>
            <xsl:when test="count(slp:Component)">
              <thead>
                <tr>
                  <th>COMPONENT</th>
                  <th>% ACTIVE TIME</th>
                  <th>ACTIVE TIME</th>
                </tr>
              </thead>
            </xsl:when>
          </xsl:choose>
          <tbody>
            <xsl:choose>
              <xsl:when test="count(slp:Component)">
                <xsl:apply-templates select="slp:Component" />
              </xsl:when>
              <xsl:otherwise>
                <td>
                  <xsl:attribute name="colspan">
                    <xsl:text>3</xsl:text>
                  </xsl:attribute>
                  <xsl:attribute name="class">
                    <xsl:text>row-</xsl:text>
                    <xsl:value-of select="@ActivityLevel" />
                  </xsl:attribute>
                  No active components.
                </td>
              </xsl:otherwise>
            </xsl:choose>
          </tbody>
        </table>
        <xsl:apply-templates select="slp:ComponentBlockers" />
        <xsl:apply-templates select="slp:CustomData" />
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Component">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <td class="center">
        <xsl:value-of select="@Index" />
      </td>
      <td class="percent">
        <xsl:call-template name="activeTimePercent">
          <xsl:with-param name="timePercent" select="@SegmentActiveTimePercent" />
        </xsl:call-template>
      </td>
      <td class="center">
        <xsl:call-template name="activeTime">
          <xsl:with-param name="time" select="@ActiveTime" />
        </xsl:call-template>
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:PepPreVetoes" mode="analysisTopLevel">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <xsl:if test="@Id">
        <xsl:attribute name="id">
          <xsl:text>offender-</xsl:text>
          <xsl:value-of select="@Id" />
        </xsl:attribute>
      </xsl:if>
      <h1>
        <span class="expander">+ </span>PEP Pre-Vetoes
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:choose>
          <xsl:when test="count(slp:Blocker)">
            <xsl:apply-templates select="slp:Blocker" />
          </xsl:when>
          <xsl:otherwise>
            <div class="analysis-empty">No PEP pre-veto activity reported.</div>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:SocSubsystems" mode="analysisTopLevel">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <xsl:if test="@Id">
        <xsl:attribute name="id">
          <xsl:text>offender-</xsl:text>
          <xsl:value-of select="@Id" />
        </xsl:attribute>
      </xsl:if>
      <h1>
        <span class="expander">+ </span>SoC Subsystems
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:choose>
          <xsl:when test="count(slp:Blocker)">
            <xsl:apply-templates select="slp:Blocker" />
          </xsl:when>
          <xsl:otherwise>
            <div class="analysis-empty">No SoC subsystem activity reported.</div>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Blockers" mode="analysisTopLevel">
    <xsl:if test="count(slp:Blocker)">
      <div>
        <xsl:attribute name="class">
          <xsl:text>analysis-container </xsl:text>
          <xsl:text>analysis-</xsl:text>
          <xsl:value-of select="@ActivityLevel" />
        </xsl:attribute>
        <h1>
          <span class="expander">+ </span>Other
        </h1>
        <div class="analysis-body-collapsed">
          <xsl:apply-templates select="slp:Blocker" />
        </div>
      </div>
    </xsl:if>
  </xsl:template>

  <xsl:template match="slp:Blocker">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <xsl:if test="@Id">
        <xsl:attribute name="id">
          <xsl:text>offender-</xsl:text>
          <xsl:value-of select="@Id" />
        </xsl:attribute>
      </xsl:if>
      <h1>
        <span class="expander">+ </span>
        <xsl:value-of select="@Name" />
      </h1>
      <div class="analysis-body-collapsed">
        <table class="defs">
          <tr>
            <td class="label">% ACTIVE TIME</td>
            <td class="label">ACTIVE TIME</td>
          </tr>
          <tr>
            <td class="percent">
              <xsl:call-template name="activeTimePercent">
                <xsl:with-param name="timePercent" select="@SegmentActiveTimePercent" />
              </xsl:call-template>
            </td>
            <td class="center">
              <xsl:call-template name="activeTime">
                <xsl:with-param name="time" select="@ActiveTime" />
              </xsl:call-template>
            </td>
          </tr>
        </table>
        <xsl:apply-templates select="slp:CustomData" />
        <xsl:apply-templates select="slp:Blocker" />
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:Blockers">
    <xsl:apply-templates select="slp:Blocker" />
  </xsl:template>

  <xsl:template match="slp:ComponentBlockers">
    <xsl:apply-templates select="slp:Blocker" />
  </xsl:template>

  <xsl:template match="slp:CustomData">
    <table class="defs">
      <xsl:apply-templates select="slp:Data" />
    </table>
  </xsl:template>

  <xsl:template match="slp:Data">
    <tr>
      <td class="label">
        <xsl:value-of select="@Key" />
      </td>
      <td>
        <xsl:value-of select="@Value" />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:SrumData" mode="analysisTopLevel">
    <h4>Srum Data</h4>
    <div class="explanation">
      Data obtained from the SRUM database.
      * in Power Estimation means the power value is from energy meter.
      Otherwise, it is from software model estimation.
    </div>

    <xsl:apply-templates select="slp:EnergyMeterData" />
    <xsl:apply-templates select="slp:PowerEstimationData" />
    <!--Restoring EnergyEstimationData.This allows the RS1 XML format to be
        successfully parsed on a machine running current RS2 and later
        builds.-->
    <xsl:apply-templates select="slp:EnergyEstimationData" />
  </xsl:template>

  <xsl:template match="slp:EnergyMeterData">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <h1>
        <span class="expander">+ </span>Energy Meter
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:choose>
          <xsl:when test="count(slp:EnergyMeterRecord) = 0">
            <div class="analysis-empty">No energy meter data obtained.</div>
          </xsl:when>
          <xsl:otherwise>
            <table class="pdc-phases">
              <thead>
                <th>Power Rail</th>
                <th>Energy (mJ)</th>
                <th>Power (mW)</th>
              </thead>
              <tbody>
                <xsl:apply-templates select="slp:EnergyMeterRecord[@EnergyConsumption != '0']">
                  <xsl:sort select="@AppId" data-type="text" order="ascending"/>
                </xsl:apply-templates>
              </tbody>
            </table>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:EnergyMeterRecord">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-info</xsl:text>
      </xsl:attribute>
      <td>
        <xsl:value-of select="@RailId" />
      </td>
      <td class="center">
        <xsl:value-of select="@EnergyConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@PowerConsumption" />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:EnergyEstimationData">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <h1>
        <span class="expander">+ </span>Energy Estimation
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:choose>
          <xsl:when test="count(slp:EnergyEstimationRecord) = 0">
            <div class="analysis-empty">No energy estimation data obtained.</div>
          </xsl:when>
          <xsl:otherwise>
            <table class="pdc-phases">
              <thead>
                <th>APP ID</th>
                <th>TOTAL (mJ)</th>
                <xsl:choose>
                  <xsl:when test="@CpuEnergyMeasured != '0'">
                    <th>CPU (mJ)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>CPU (mJ)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@DisplayEnergyMeasured != '0'">
                    <th>DISPLAY (mJ)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>DISPLAY (mJ)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@DiskEnergyMeasured != '0'">
                    <th>DISK (mJ)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>DISK (mJ)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@MbbEnergyMeasured != '0'">
                    <th>MBB (mJ)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>MBB (mJ)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@NetworkEnergyMeasured != '0'">
                    <th>NETWORK (mJ)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>NETWORK (mJ)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@SocEnergyMeasured != '0'">
                    <th>SOC (mJ)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>SOC (mJ)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <th>LOSS (mJ)</th>
                <th>OTHER (mJ)</th>
              </thead>
              <tbody>
                <xsl:apply-templates select="slp:EnergyEstimationRecord[@TotalEnergyConsumption != '0']">
                  <xsl:sort select="@TotalEnergyConsumption" data-type="number" order="descending"/>
                </xsl:apply-templates>
              </tbody>
            </table>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:EnergyEstimationRecord">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-info</xsl:text>
      </xsl:attribute>
      <td>
        <xsl:value-of select="@AppId" /> [<xsl:value-of select="@UserId" />]
      </td>
      <td class="center">
        <xsl:value-of select="@TotalEnergyConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@CpuEnergyConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@DisplayEnergyConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@DiskEnergyConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@MbbEnergyConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@NetworkEnergyConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@SocEnergyConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@LossEnergyConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@OtherEnergyConsumption" />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:PowerEstimationData">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:text>analysis-</xsl:text>
        <xsl:value-of select="@ActivityLevel" />
      </xsl:attribute>
      <h1>
        <span class="expander">+ </span>Power Estimation
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:choose>
          <xsl:when test="count(slp:PowerEstimationRecord) = 0">
            <div class="analysis-empty">No power estimation data obtained.</div>
          </xsl:when>
          <xsl:otherwise>
            <table class="pdc-phases">
              <thead>
                <th>APP ID</th>
                <th>TOTAL (mW)</th>
                <xsl:choose>
                  <xsl:when test="@CpuEnergyMeasured != '0'">
                    <th>CPU (mW)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>CPU (mW)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@DisplayEnergyMeasured != '0'">
                    <th>DISPLAY (mW)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>DISPLAY (mW)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@DiskEnergyMeasured != '0'">
                    <th>DISK (mW)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>DISK (mW)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@MbbEnergyMeasured != '0'">
                    <th>MBB (mW)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>MBB (mW)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@NetworkEnergyMeasured != '0'">
                    <th>NETWORK (mW)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>NETWORK (mW)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
                  <xsl:when test="@SocEnergyMeasured != '0'">
                    <th>SOC (mW)*</th>
                  </xsl:when>
                  <xsl:otherwise>
                    <th>SOC (mW)</th>
                  </xsl:otherwise>
                </xsl:choose>
                <th>LOSS (mW)</th>
                <th>OTHER (mW)</th>
              </thead>
              <tbody>
                <xsl:apply-templates select="slp:PowerEstimationRecord[@TotalPowerConsumption != '0']">
                  <xsl:sort select="@TotalPowerConsumption" data-type="number" order="descending"/>
                </xsl:apply-templates>
              </tbody>
            </table>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="slp:PowerEstimationRecord">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-info</xsl:text>
      </xsl:attribute>
      <td>
        <xsl:value-of select="@AppId" /> [<xsl:value-of select="@UserId" />]
      </td>
      <td class="center">
        <xsl:value-of select="@TotalPowerConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@CpuPowerConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@DisplayPowerConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@DiskPowerConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@MbbPowerConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@NetworkPowerConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@SocPowerConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@LossPowerConsumption" />
      </td>
      <td class="center">
        <xsl:value-of select="@OtherPowerConsumption" />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:SearchIndexerData">
    <xsl:if test="*">
      <h4>Search Indexer Data</h4>
      <xsl:if test="count(slp:Query) > 0">
        <div>
          <xsl:attribute name="class">
            <xsl:text>analysis-container analysis-info</xsl:text>
          </xsl:attribute>
          <h1>
            <span class="expander">+ </span>Query Events:
            <xsl:value-of select="slp:Query/@TotalNumberOfEvents" />
          </h1>
          <div class="analysis-body-collapsed">
            <table class="pdc-phases">
              <thead>
                <th>Max Cursors Used</th>
                <th>Protocol Count</th>
                <th>Protocol String</th>
              </thead>
              <tbody>
                <xsl:apply-templates select="slp:Query" />
              </tbody>
            </table>
          </div>
        </div>
      </xsl:if>

      <xsl:if test="count(slp:Flush) > 0">
        <div>
          <xsl:attribute name="class">
            <xsl:text>analysis-container analysis-info</xsl:text>
          </xsl:attribute>
          <h1>
            <span class="expander">+ </span>Flush Events:
            <xsl:value-of select="slp:Flush/@TotalNumberOfEvents" />
          </h1>
          <div class="analysis-body-collapsed">
            <table class="pdc-phases">
              <thead>
                <th>Max Key Count</th>
                <th>Max Documents</th>
                <th>Max Word List</th>
              </thead>
              <tbody>
                <xsl:apply-templates select="slp:Flush" />
              </tbody>
            </table>
          </div>
        </div>
      </xsl:if>

      <xsl:if test="count(slp:Merge) > 0">
        <div>
          <xsl:attribute name="class">
            <xsl:text>analysis-container analysis-info</xsl:text>
          </xsl:attribute>
          <h1>
            <span class="expander">+ </span>Merge Events:
            <xsl:value-of select="slp:Merge/@TotalNumberOfEvents" />
          </h1>
          <div class="analysis-body-collapsed">
            <table class="pdc-phases">
              <thead>
                <th>Pre-Merge Indice Count</th>
                <th>Pre-Merge Level</th>
                <th>Pre-Merge Min ID</th>
                <th>Pre-Merge Max ID</th>
                <th>Post-Merge Indice Count</th>
                <th>Post-Merge Level</th>
                <th>Post-Merge Min ID</th>
                <th>Post-Merge Max ID</th>
              </thead>
              <tbody>
                <xsl:apply-templates select="slp:Merge" />
              </tbody>
            </table>
          </div>
        </div>
      </xsl:if>

      <xsl:if test="count(slp:FileSysChange) > 0">
        <div>
          <xsl:attribute name="class">
            <xsl:text>analysis-container analysis-info</xsl:text>
          </xsl:attribute>
          <h1>
            <span class="expander">+ </span>File System Change Events:
            <xsl:value-of select="slp:FileSysChange/@TotalNumberOfEvents" />
          </h1>
          <div class="analysis-body-collapsed">
            <table class="pdc-phases">
              <thead>
                <th>FAT Items Processed</th>
                <th>NTFS Items Processed</th>
              </thead>
              <tbody>
                <xsl:apply-templates select="slp:FileSysChange" />
              </tbody>
            </table>
          </div>
        </div>
      </xsl:if>

      <xsl:if test="count(slp:IndexingFile) > 0">
        <div>
          <xsl:attribute name="class">
            <xsl:text>analysis-container analysis-info</xsl:text>
          </xsl:attribute>
          <h1>
            <span class="expander">+ </span>Indexing File Events:
            <xsl:value-of select="slp:IndexingFile/@TotalNumberOfEvents" />
          </h1>
          <div class="analysis-body-collapsed">
            <table class="pdc-phases">
              <thead>
                <th>IndexingFile Aggregation Data Metric</th>
                <th>Content Type Count</th>
                <th>Content Type String</th>
              </thead>
              <tbody>
                <xsl:apply-templates select="slp:IndexingFile" />
              </tbody>
            </table>
          </div>
        </div>
      </xsl:if>

      <xsl:if test="count(slp:EnteringIdle) > 0">
        <div>
          <xsl:attribute name="class">
            <xsl:text>analysis-container analysis-info</xsl:text>
          </xsl:attribute>
          <h1>
            <span class="expander">- </span>Entering Idle Events:
            <xsl:value-of select="slp:EnteringIdle/@TotalNumberOfEvents" />
          </h1>
        </div>
      </xsl:if>

      <xsl:if test="count(slp:QueryResults) > 0">
        <div>
          <xsl:attribute name="class">
            <xsl:text>analysis-container analysis-info</xsl:text>
          </xsl:attribute>
          <h1>
            <span class="expander">+ </span>Query Results Events:
            <xsl:value-of select="slp:QueryResults/@TotalNumberOfEvents" />
          </h1>
          <div class="analysis-body-collapsed">
            <table class="pdc-phases">
              <thead>
                <th>Results Requested</th>
                <th>Results Returned</th>
              </thead>
              <tbody>
                <xsl:apply-templates select="slp:QueryResults" />
              </tbody>
            </table>
          </div>
        </div>
      </xsl:if>
    </xsl:if>
  </xsl:template>

  <xsl:template match="slp:Query">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-info</xsl:text>
      </xsl:attribute>
      <td class="center">
        <xsl:value-of select="@MaxCursorsUsed" />
      </td>
      <td class="center">
        <xsl:value-of select="@ProtocolCount" />
      </td>
      <td class="center">
        <xsl:value-of select="@ProtocolString" />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:Flush">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-info</xsl:text>
      </xsl:attribute>
      <td class="center">
        <xsl:value-of select="@MaxKeyCount" />
      </td>
      <td class="center">
        <xsl:value-of select="@MaxDocuments" />
      </td>
      <td class="center">
        <xsl:value-of select="@MaxWordList" />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:Merge">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-info</xsl:text>
      </xsl:attribute>
      <td class="center">
        <xsl:value-of select="@PreMergeIndiceCount" />
      </td>
      <td class="center">
        <xsl:value-of select="@PreMergeLevel" />
      </td>
      <td class="center">
        <xsl:value-of select="@PreMergeMinId" />
      </td>
      <td class="center">
        <xsl:value-of select="@PreMergeMaxId" />
      </td>
      <td class="center">
        <xsl:value-of select="@PostMergeIndiceCount" />
      </td>
      <td class="center">
        <xsl:value-of select="@PostMergeLevel" />
      </td>
      <td class="center">
        <xsl:value-of select="@PostMergeMinId" />
      </td>
      <td class="center">
        <xsl:value-of select="@PostMergeMaxId" />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:FileSysChange">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-info</xsl:text>
      </xsl:attribute>
      <td class="center">
        <xsl:value-of select="@TotalFATItemsProcessed" />
      </td>
      <td class="center">
        <xsl:value-of select="@TotalNTFSItemsProcessed" />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:IndexingFile">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-info</xsl:text>
      </xsl:attribute>
       <td class="center">
        <xsl:value-of select="@IndexingFileAggregationDataMetric" />
      </td>
      <td class="center">
        <xsl:value-of select="@DataTypeCount" />
      </td>
      <td class="center">
        <xsl:value-of select="@DataTypeString" />
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="slp:QueryResults">
    <tr>
      <xsl:attribute name="class">
        <xsl:text>row-info</xsl:text>
      </xsl:attribute>
      <td class="center">
        <xsl:value-of select="@TotalResultsRequested" />
      </td>
      <td class="center">
        <xsl:value-of select="@TotalResultsReturned" />
      </td>
    </tr>
  </xsl:template>

  <!-- Screen on detailed data -->
  <xsl:template match="slp:RecentUsageInstance" mode="analysisResults">
    <xsl-text></xsl-text>
    <a>
      <xsl:attribute name="name">
        <xsl:text>connected-standby-session-</xsl:text>
        <xsl:value-of select="position()" />
      </xsl:attribute>
    </a>
    <div class="scroll-top-button">Top</div>
    <h3>
      System Power State:  <xsl:value-of select="@Type" />
    </h3>
    <table class="session-summary">
      <colgroup>
        <col style="width: 2em" />
        <col style="width: 11em;" />
        <col style="width: 5em;" />
        <col style="width: 10em;" />
        <col class="width: 13em;" />
        <col class="width: 13em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
        <col style="width: 6em;" />
      </colgroup>
      <thead>
        <tr>
          <th></th>
          <th>START TIME</th>
          <th>DURATION</th>
          <th>STATE</th>
          <th colspan="2">ENERGY CHANGE</th>
          <th colspan="2">CHANGE RATE</th>
          <th colspan="2">% LOW POWER STATE TIME</th>
          <th>% CAPACITY REMAINING AT START</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <xsl:attribute name="class">
            <xsl:text>row-</xsl:text>
            <xsl:value-of select="@ActivityLevel" />
          </xsl:attribute>
          <td class="centered">
            <xsl:value-of select="position()" />
          </td>
          <td class="dateTime">
            <xsl:call-template name="formatDateTime">
              <xsl:with-param name="dateTime" select="@LocalTimestamp" />
            </xsl:call-template>
          </td>
          <td class="hms">
            <xsl:value-of select="js:formatDurationMs(string(@Duration div 10000))" />
          </td>

          <!-- State -->
          <td class="state">
            <xsl:value-of select="@Type" />
          </td>

          <!-- Energy change -->
          <xsl:call-template name="mWhCell">
            <xsl:with-param name="batteryDrain" select="@Discharge" />
            <xsl:with-param name="batteryCapacity" select="@FullChargeCapacity" />
            <xsl:with-param name="batteryCountChanged" select="@BatteryCountChanged" />
          </xsl:call-template>

          <!-- Change rate -->
          <xsl:call-template name="mWCell">
            <xsl:with-param name="energyDrain" select="@EnergyDrain" />
            <xsl:with-param name="batteryCountChanged" select="@BatteryCountChanged" />
          </xsl:call-template>

          <!-- Charge/Drain -->
          <td class="chargeOrDrain">
            <xsl:value-of select="js:createChargeDrainString(string(@Ac), '17')" />
          </td>

          <!-- % Low Power State Time -->
          <td class="nullValue" colspan="2">-</td>

          <!-- Start Capacity remaining -->
          <xsl:call-template name="percentCell">
            <xsl:with-param name="remainingCapacity" select="@EntryRemainingCapacity" />
            <xsl:with-param name="fullCapacity" select="@EntryFullCapacity" />
            <xsl:with-param name="batteryCountChanged" select="@BatteryCountChanged" />
          </xsl:call-template>
        </tr>
      </tbody>
    </table>

    <xsl:if test="slp:ScreenOnSessionGuid">
      <h4>
        <xsl:value-of select="concat('Session ID: ', slp:ScreenOnSessionGuid)"/>
      </h4>
    </xsl:if>
    <xsl:if test="slp:ScreenOnEntryReason">
      <h4>
        <xsl:value-of select="concat('Entry reason: ', slp:ScreenOnEntryReason)"/>
      </h4>
    </xsl:if>
    <xsl:if test="slp:ScreenOnExitReason">
      <h4>
        <xsl:value-of select="concat('Exit reason: ', slp:ScreenOnExitReason)"/>
      </h4>
    </xsl:if>

    <xsl:if test="slp:ScreenBrightnessHistogram">
      <h4>Screen Brightness Duration Histogram</h4>
      <div class="explanation">Duration in seconds at various screen brightness levels</div>
      <canvas>
        <xsl:attribute name="id">
          <xsl:text>brightness-duration-</xsl:text>
          <xsl:value-of select="position()" />
        </xsl:attribute>
        <xsl:attribute name="width">
          <xsl:text>864</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="height">
          <xsl:text>300</xsl:text>
        </xsl:attribute>
        <xsl:text> </xsl:text>
      </canvas>
    </xsl:if>

    <xsl:if test="slp:LuxHistogram">
      <h4>Lux Duration Histogram</h4>
      <div class="explanation">Duration in seconds at various lux levels</div>
      <canvas>
        <xsl:attribute name="id">
          <xsl:text>lux-duration-</xsl:text>
          <xsl:value-of select="position()" />
        </xsl:attribute>
        <xsl:attribute name="width">
          <xsl:text>864</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="height">
          <xsl:text>300</xsl:text>
        </xsl:attribute>
        <xsl:text> </xsl:text>
      </canvas>
    </xsl:if>

    <xsl:apply-templates select="slp:SearchIndexerData" />
    <xsl:apply-templates select="slp:SrumData" mode="analysisTopLevel" />
  </xsl:template>


  <!-- The list of installed batteries -->
  <xsl:template match="slp:Batteries" >
    <!-- Look only at "long term" batteries (i.e. not UPS batteries) -->
    <xsl:variable name="longTermBatts" select="slp:Battery[slp:LongTerm != 0]" />

    <h2>
      Installed batteries
    </h2>
    <div class="explanation">
      Information about each currently installed battery
    </div>

    <xsl:choose>
      <xsl:when test="count($longTermBatts) = 0">
        <!-- No batteries currently installed -->
        <div class="nobatts">
          No batteries are currently installed.
        </div>
      </xsl:when>
      <xsl:otherwise>
        <table class="defs">
          <colgroup>
            <col style="width: 15em;" />
            <xsl:for-each select="$longTermBatts">
              <col style="width: 14em;" />
            </xsl:for-each>
          </colgroup>
          <thead>
            <tr>
              <td>
                <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
                <xsl:text> </xsl:text>
              </td>
              <xsl:for-each select="$longTermBatts">
                <td>
                  BATTERY
                  <xsl:value-of select="position()"/>
                </td>
              </xsl:for-each>
            </tr>
          </thead>
          <tr>
            <td>
              <span class="label">NAME</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:call-template name="dashIfEmpty">
                  <xsl:with-param name="str" select="slp:Id"/>
                </xsl:call-template>
              </td>
            </xsl:for-each>
          </tr>
          <tr>
            <td>
              <span class="label">MANUFACTURER</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:call-template name="dashIfEmpty">
                  <xsl:with-param name="str" select="slp:Manufacturer"/>
                </xsl:call-template>
              </td>
            </xsl:for-each>
          </tr>
          <tr>
            <td>
              <span class="label">SERIAL NUMBER</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:call-template name="dashIfEmpty">
                  <xsl:with-param name="str" select="slp:SerialNumber"/>
                </xsl:call-template>
              </td>
            </xsl:for-each>
          </tr>
          <tr>
            <td>
              <span class="label">CHEMISTRY</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:call-template name="dashIfEmpty">
                  <xsl:with-param name="str" select="slp:Chemistry"/>
                </xsl:call-template>
              </td>
            </xsl:for-each>
          </tr>
          <tr>
            <td>
              <span class="label">DESIGN CAPACITY</span>
            </td>

            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:choose>
                  <!-- If RelativeCapacity=1, the units reported for the battery are not mWh -->
                  <xsl:when test="slp:RelativeCapacity = 1">
                    -
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:call-template name="mWh">
                      <xsl:with-param name="value" select="slp:DesignCapacity"/>
                    </xsl:call-template>
                  </xsl:otherwise>
                </xsl:choose>
              </td>
            </xsl:for-each>
          </tr>

          <!-- Small break to hint that the next 2 values are special (they can change over time) -->
          <tr style="height:0.4em;"></tr>

          <tr>
            <td>
              <span class="label">CAPACITY RATIO</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:value-of select="round(100 * slp:FullChargeCapacity div slp:DesignCapacity)" />%
              </td>
            </xsl:for-each>
          </tr>

          <tr>
            <td>
              <span class="label">CYCLE COUNT</span>
            </td>
            <xsl:for-each select="$longTermBatts">
              <td>
                <xsl:call-template name="dashIfEmpty">
                  <xsl:with-param name="str" select="slp:CycleCount"/>
                </xsl:call-template>
              </td>
            </xsl:for-each>
          </tr>
        </table>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Matches the root node. This starts the XSL processing. -->
  <xsl:template match="/" >

    <html>
      <head>
        <!-- Support the latest IE -->
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />

        <!-- All times are displayed using local time. Store the offset at which the report was generated in
             case someone needs to calculate the UTC times (although this is not entirely sufficient if the
             machine has moved timezones during the report period. -->
        <meta name="ReportUtcOffset" content="{$reportInfo/slp:UtcOffset}" />

        <title>System Power Report</title>

        <!-- CSS styles -->
        <xsl:call-template name="css"/>

        <!-- JavaScript -->
        <xsl:call-template name="javascript">
          <xsl:with-param name="sessions" select="/slp:SleepStudy/slp:ScenarioInstances" />
          <xsl:with-param name="dripsBuckets" select="/slp:SleepStudy/slp:ScenarioInstances/slp:ScenarioInstance/slp:DripsBuckets" />
          <xsl:with-param name="energyDrains" select="/slp:SleepStudy/slp:EnergyDrains" />
        </xsl:call-template>
      </head>

      <body>

        <h1>System Power Report</h1>

        <!-- Report warnings, if any -->
        <xsl:apply-templates select="/slp:SleepStudy/slp:Warnings" />

        <!-- Describe the machine -->
        <xsl:call-template name="systemInformation" />

        <!-- Summary Table -->
        <xsl:if test="$singleTraceFile = 'false'">
          <h2>System Power State Transitions</h2>
          <xsl:choose>
            <xsl:when test="boolean(/slp:SleepStudy/slp:EnergyDrains)">
              <div class="explanation">
                Battery drains over the last <xsl:value-of select="$reportDuration" /> days
              </div>
              <xsl:call-template name="batteryDrainGraph" />
            </xsl:when>
            <xsl:otherwise>
              <div class="explanation">
                Connected Standby transitions over the last <xsl:value-of select="$reportDuration" /> days
              </div>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:apply-templates select="/slp:SleepStudy/slp:ScenarioInstances" mode="summaryTable" />
        </xsl:if>

        <!-- Analysis results -->
        <h2>Analysis Results</h2>
        <div class="explanation">Analysis of issues that might cause poor battery life</div>
        <xsl:apply-templates select="/slp:SleepStudy/slp:ScenarioInstances" mode="analysisResults" />

        <!-- Installed batteries -->
        <xsl:apply-templates select="/slp:SleepStudy/slp:Batteries" />

        <br />
        <br />
        <br />
      </body>
    </html>
  </xsl:template>

  <!-- Formats a date-time for display -->
  <xsl:template name="formatDateTime">
    <xsl:param name="dateTime"/>
    <xsl:param name="showDate" select="true()" />
    <xsl:variable name="date" select="substring-before($dateTime, 'T')"/>
    <xsl:variable name="time" select="translate(substring-after($dateTime, 'T'), 'T ', '')"/>

    <span class="date">
      <xsl:if test="$showDate">
        <xsl:value-of select="$date"/>
      </xsl:if>
      <!-- Include some space so that the tag doesn't self-close (HTML requirement) -->
      <xsl:text> </xsl:text>
    </span>
    <span class="time">
      <xsl:value-of select="$time"/>
    </span>
  </xsl:template>

  <!-- Outputs the given string, or a dash ('-') if the string is empty -->
  <xsl:template name="dashIfEmpty">
    <xsl:param name="str"/>
    <xsl:variable name="s" select="normalize-space($str)" />
    <xsl:choose>
      <xsl:when test="string-length($s) = 0">
        -
      </xsl:when>
      <xsl:when test="$s = '0'">
        -
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$s"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Formats a mWh value -->
  <xsl:template name="mWh">
    <xsl:param name="value"/>
    <xsl:variable name="number" select="number($value)" />
    <xsl:choose>
      <!-- Test for not NaN, not 0, and not Infinity -->
      <xsl:when test="$number != 0 and $number = $number and $number != (1 div 0) and $number != (-1 div 0)">
        <xsl:value-of select="js:numberToLocaleString($number)"/> mWh
      </xsl:when>
      <xsl:otherwise>
        -
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Formats a mWh value for a table cell -->
  <xsl:template name="mWhCell">
    <xsl:param name="batteryDrain"/>
    <xsl:param name="batteryCapacity"/>
    <xsl:param name="batteryCountChanged"/>
    <xsl:choose>
      <!-- Test for not NaN, not 0, and not Infinity -->
      <xsl:when test="($batteryCountChanged = 0 and $batteryDrain &gt; 0 and $batteryDrain = $batteryDrain and $batteryDrain != (1 div 0) and $batteryDrain != (-1 div 0))
                      and ($batteryCapacity != 0 and $batteryCapacity = $batteryCapacity and $batteryCapacity != (1 div 0) and $batteryCapacity != (-1 div 0))">
        <td class="mw">
          <xsl:value-of select="js:numberToLocaleString(number($batteryDrain))"/> mWh
        </td>
        <td class="mw">
          <xsl:value-of select="js:numberToLocaleString(round(100 * $batteryDrain div $batteryCapacity))"/>% of battery
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td class="nullValue">-</td>
        <td class="nullValue">-</td>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Formats a % value -->
  <xsl:template name="percent">
    <xsl:param name="value"/>
    <xsl:choose>
      <xsl:when test="$value &gt; 0 and $value &lt; (1 div 0)">
        <xsl:value-of select="$value"/>%
      </xsl:when>
      <xsl:otherwise>-</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Formats an energy value for a table cell -->
  <xsl:template name="mWCell">
    <xsl:param name="energyDrain" />
    <xsl:param name="batteryCountChanged"/>
    <xsl:choose>
      <xsl:when test="($batteryCountChanged = 0 and $energyDrain &gt; 0 and $energyDrain &lt; (1 div 0))">
        <td class="mw">
          <xsl:value-of select="js:numberToLocaleString(round($energyDrain))"/> mW
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td class="nullValue">-</td>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Formats a % value for a table cell -->
  <xsl:template name="percentCell">
    <xsl:param name="remainingCapacity"/>
    <xsl:param name="fullCapacity"/>
    <xsl:param name="batteryCountChanged"/>
    <xsl:choose>
      <!-- Test for not NaN, not 0, and not Infinity -->
      <xsl:when test="($batteryCountChanged = 0 and $remainingCapacity &gt; 0 and $remainingCapacity = $remainingCapacity and $remainingCapacity != (1 div 0) and $remainingCapacity != (-1 div 0))
                      and ($fullCapacity != 0 and $fullCapacity = $fullCapacity and $fullCapacity != (1 div 0) and $fullCapacity != (-1 div 0))">
        <td class="mw">
          <xsl:value-of select="js:numberToLocaleString(round(100 * $remainingCapacity div $fullCapacity))"/>%
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td class="nullValue">-</td>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Formats the DRIPS Wake Reasons table entry -->
  <xsl:template match="slp:DripsWakeSources">
    <div>
      <xsl:attribute name="class">
        <xsl:text>analysis-container </xsl:text>
        <xsl:choose>
          <xsl:when test="count(slp:DripsWakeSource) = 0">
            <xsl:text>analysis-neutral</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>analysis-info</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <h1>
        <span class="expander">+ </span>DRIPS Wake Sources
      </h1>
      <div class="analysis-body-collapsed">
        <xsl:choose>
          <xsl:when test="count(slp:DripsWakeSource) = 0">
            <div class="analysis-empty">No DRIPS wake source information obtained.</div>
          </xsl:when>
          <xsl:otherwise>
            <table class="pdc-phases">
              <thead>
                <th>WAKE SOURCE</th>
                <th>WAKE TYPE</th>
                <th>COUNT</th>
              </thead>
              <tbody>
                <xsl:for-each select="slp:DripsWakeSource">
                  <xsl:sort select="@Count" data-type="number" order="descending" />
                  <tr class="row-info">
                    <td>
                      <xsl:value-of select="@ReasonDescription" />
                    </td>
                    <td class="center">
                      <xsl:value-of select="@Type" />
                    </td>
                    <td class="center">
                      <xsl:value-of select="js:numberToLocaleString(number(@Count))" />
                    </td>
                  </tr>
                </xsl:for-each>
              </tbody>
            </table>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>

  <ms:script implements-prefix="js">
    <![CDATA[
    // Formats a number using the current locale (to handle the 1000's separator).
    // The result is rounded so no decimal point is shown.
    function numberToLocaleString(value) {
      var localeString = Math.round(parseFloat(value + '')).toLocaleString();
      return localeString.substring(0, localeString.indexOf('.'));
    }

    function padLeft(number, length) {
      var str = '' + number;
      while (str.length < length) {
        str = '0' + str;
      }
      return str;
    }

    // Returns the number of milliseconds between 2 date-times represented as strings.
    function msBetween(startTime, endTime) {
      return startTime > endTime
          ? msBetween(endTime, startTime)
          : parseDateTime(endTime) - parseDateTime(startTime);
    }


    var dateFormat = /(\d{4})-(\d{2})-(\d{2})[T](\d{2}):(\d{2}):(\d{2})/

    // Parses a date-time string and returns a Date (i.e. number of milliseconds)
    function parseDateTime(value) {
      if (!value) {
        return 0;
      }
      var match = dateFormat.exec(value)
      if (!match) {
        return 0;
      }
      return Date.parse(match[1] + '/' + match[2] + '/' + match[3] + ' ' + match[4] + ':' + match[5] + ':' + match[6])
    }

    // Parses just the date portion of a date-time string and returns a Date (i.e. number of milliseconds)
    function parseDate(value) {
      if (!value) {
        return 0;
      }
      var match = dateFormat.exec(value)
      if (!match) {
        return 0;
      }
      return Date.parse(match[1] + '/' + match[2] + '/' + match[3])
    }

    var durationFormat = /P((\d+)D)?T((\d+)H)?((\d+)M)?(\d+)S/

    // Convert a string of the form P10DT1H15M40S to a count of milliseconds
    function parseDurationToMs(value) {
      var match = durationFormat.exec(value)
      if (!match) {
        return 0
      }
      var days = parseInt(match[2] || '0');
      var hrs = parseInt(match[4] || '0');
      var mins = parseInt(match[6] || '0');
      var secs = parseInt(match[7] || '0');
      return ((((((days * 24) + hrs) * 60) + mins) * 60) +  secs) * 1000;
    }

    // Formats a number of milliseconds as h:mm:ss
    function formatDurationMs(value) {
      var ms = parseInt(value);
      var secs = ms / 1000;
      var mins = secs / 60;
      var hrs = Math.floor(mins / 60);
      mins = Math.floor(mins % 60);
      secs = Math.floor(secs % 60);
      return hrs + ':' + padLeft(mins,2) + ':' + padLeft(secs,2);
    }

    // Converts a string representing a date time to a day and month string
    function dateToDayAndMonth(date, dayOffset) {
      var adjustedDate = new Date(parseDate(date) - (dayOffset * 24 * 60 * 60 * 1000));
      return padLeft(adjustedDate.toLocaleDateString());
    }

    // Format Charge and Drain strings that sometimes reflect extra text
    // for special cases around transitioning from CS to S4/S5 due to:
    // - transitioning to S4 due to a critically low battery,
    // - transitioning to S4 or S5 due to a thermal condition,
    // - doze to S4 after a specified duration in CS.
    function createChargeDrainString(onAc, scenarioStopReason) {
        var _onAc = parseInt(onAc);                             // BOOLEAN
        var _scenarioStopReason = parseInt(scenarioStopReason); // SLEEPSTUDY_SPM_SCENARIO_STOP_REASON
        var str;
        if (_onAc) {
            str = 'Charge';
        } else {
            str = 'Drain';
        }

        if(onAc == -1) {
            str ='-';
        }

        if (_scenarioStopReason == 1) {             // PolicyDeviceThermalZone
            str = str + ' (thermal)';
        } else if (_scenarioStopReason == 2) {      // PolicyDeviceBattery
            str = str + ' (critical battery)';
        } else if (_scenarioStopReason == 6) {      // PolicyImmediateDozeS4
            str = str + ' (dozed to hibernate)';
        } else if (_scenarioStopReason == 11) {      // PolicyImmediateDozeS4Predicted
            str = str + ' (dozed to hibernate because the user was predicted to be away)';
        } else if (_scenarioStopReason == 12) {      // PolicyImmediateDozeS4PredictedNoWake
            str = str + ' (dozed to hibernate because the user was predicted to be away)';
        } else if (_scenarioStopReason == 13) {      // PolicyImmediateDozeS4AdaptiveBudget
            str = str + ' (dozed to hibernate because the standby battery budget was exceeded)';
        } else if (_scenarioStopReason == 14) {      // PolicyImmediateDozeS4AdaptiveReserveNoWake
            str = str + ' (dozed to hibernate because the reserve battery level was reached)';
        } else if (_scenarioStopReason == 16) {     // SpmScenarioStopReasonUnspecified
            str = str + ' (unspecified sleep reason)';
        } else if (_scenarioStopReason == 17) {     // SpmScenarioStopReasonCsExit
            str = str;      // nop
        } else if (_scenarioStopReason == 18) {     // SpmScenarioStopReasonInternalSegmentTransition
            str = str;      // nop
        } else {
            str = str + ' (unrecognized sleep reason ' + _scenarioStopReason + ')';
        }

        return str;
    }
    ]]>
  </ms:script>
</xsl:stylesheet>
PADPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPAD