home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / WindowsServerTrial / server.iso / sources / install.wim / 2 / Windows / System32 / en-US / EventViewer_EventDetails.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2008-01-19  |  18.0 KB  |  513 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3.  
  4. <!-- The indent for child nodes -->
  5. <xsl:variable name="indent">15</xsl:variable>
  6.  
  7. <!-- The indent for attributes -->
  8. <xsl:variable name="AttributeIndent">12</xsl:variable>
  9.  
  10. <!-- The font and font size to be used. -->
  11. <xsl:variable name="FontFamily">Segoe UI</xsl:variable>
  12. <xsl:variable name="FontFamily_FixWidth">Courier New</xsl:variable>
  13. <xsl:variable name="FontSize">11</xsl:variable>
  14. <xsl:variable name="FontStyle">font-family: 'Segoe UI'; font-size: '11';</xsl:variable>
  15.  
  16. <!-- Vertical align style of table items. -->
  17. <xsl:variable name="VerticalAlignStyle">vertical-align: top;</xsl:variable>
  18.  
  19. <!-- The width for + and - sign column -->
  20. <xsl:variable name="SignColumnWidth">15</xsl:variable>
  21.  
  22. <!-- The element name column width -->
  23. <xsl:variable name="ElementNameColumnWidth">130</xsl:variable>
  24.  
  25. <!-- The attribute name column width -->
  26. <xsl:variable name="AttributeNameColumnWidth">105</xsl:variable>
  27.  
  28. <!-- _locID_text="WordsFormat" -->
  29. <xsl:variable name="WordsFormat">In Words</xsl:variable>
  30.  
  31. <!-- _locID_text="BytesFormat" -->
  32. <xsl:variable name="BytesFormat">In Bytes</xsl:variable>
  33.  
  34. <xsl:template match="/*">   <!-- Match /Event, regardless of namespace -->
  35.  
  36. <html>
  37. <head>
  38.   <meta http-equiv="Content-Script-Type" content="text/javascript"/>
  39.   <script>
  40.   <![CDATA[
  41.     function Toggle(node)
  42.     {
  43.       if (!window.fullyLoaded) return;
  44.  
  45.       // Expand the branch?
  46.       if (node.nextSibling.style.display == 'none')
  47.       {
  48.         // Change the sign from "+" to "-".
  49.         var tBodyNode = node.childNodes[0];
  50.         var trNode = tBodyNode.childNodes[0];
  51.         var tdNode = trNode.childNodes[0];
  52.         var bNode = tdNode.childNodes[0];
  53.         var textNode = bNode.childNodes[0];
  54.         if (textNode.nodeType == 3 /* Node.TEXT_NODE */) {
  55.           var s = textNode.data;
  56.           if (s.length > 0 && s.charAt(0) == '+') {
  57.             textNode.data = '-' + s.substring(1, s.length);
  58.           }
  59.         }
  60.  
  61.         // show the branch
  62.         node.nextSibling.style.display = '';
  63.       }
  64.       else // Collapse the branch
  65.       {
  66.         // Change the sign from "-" to "+".
  67.         var tBodyNode = node.childNodes[0];
  68.         var trNode = tBodyNode.childNodes[0];
  69.         var tdNode = trNode.childNodes[0];
  70.         var bNode = tdNode.childNodes[0];
  71.         var textNode = bNode.childNodes[0];
  72.         if (textNode.nodeType == 3 /* Node.TEXT_NODE */) {
  73.           var s = textNode.data;
  74.           if (s.length > 0 && s.charAt(0) == '-') {
  75.             textNode.data = '+' + s.substring(1, s.length);
  76.           }
  77.         }
  78.  
  79.         // hide the branch
  80.         node.nextSibling.style.display = 'none';
  81.       }
  82.     }
  83.  
  84.     // Toggle "System" element by default so that it's default status is to hide its children
  85.     function ToggleSystemElement()
  86.     {
  87.       var body = document.getElementById("body");
  88.       var anchor = body.getElementsByTagName("table")[0];
  89.       Toggle(anchor);
  90.     }
  91.  
  92.     // If binary data is present in event XML, show it in friendly form.
  93.     function ProcessBinaryData(binaryString, binaryDataCaption, wordsFormatString, bytesFormatString, normalFont, fixedWidthFont)
  94.     {
  95.       var bodyNode = document.getElementById("body");
  96.  
  97.       // Add a <hr> at the end of the HTML body.
  98.       bodyNode.appendChild(document.createElement("hr"));      
  99.  
  100.       // This paragraph (p element) is the "Binary data:" literal string.
  101.       var p = document.createElement("p");
  102.       p.style.fontFamily = normalFont;
  103.       var b = document.createElement("b");
  104.       b.appendChild(document.createTextNode(binaryDataCaption));
  105.       p.appendChild(b);
  106.       p.appendChild(document.createElement("br"));
  107.       bodyNode.appendChild(p);
  108.  
  109.       //
  110.       // Show binary data in Words format.
  111.       //
  112.       p = document.createElement("p");
  113.       p.style.fontFamily = normalFont;
  114.       p.appendChild(document.createTextNode(wordsFormatString));
  115.       bodyNode.appendChild(p);
  116.  
  117.       // Must use fixed-width font for binary data.
  118.       p = document.createElement("p");
  119.       p.style.fontFamily = fixedWidthFont;
  120.     
  121.       var i = 0;
  122.       var j = 0;
  123.       var s, tempS;
  124.       var translatedString;
  125.       var charCode;
  126.       var byte1, byte2;
  127.  
  128.       // Each character in binaryString is a hex (16-based) representation of
  129.       // 4 binary bits. So it takes 2 characters in binaryString to form a
  130.       // complete byte; 4 characters for a word.
  131.       while (i < binaryString.length) {
  132.  
  133.         s = (i / 4).toString(16);    // To hex representation.
  134.         while (s.length < 4) {
  135.           s = "0" + s;
  136.         }
  137.         s += ": ";
  138.  
  139.         // DWords representation is simply a rearrangement of the original binaryString
  140.         // For example, from:
  141.         // 
  142.         // 0000000002005600000000000f000540
  143.         //
  144.         // (which is 00 00 00 00 02 00 56 00 00 00 00 00 0f 00 05 40).
  145.         //
  146.         // to:
  147.         //
  148.         // 0000: 00000000 00560002 00000000 4005000f
  149.         // 8 words per line, 4 DWords per line.
  150.         for (j = 0; j < 4; j++) {
  151.           s += binaryString.substring(i + 6, i + 8);
  152.           s += binaryString.substring(i + 4, i + 6);
  153.           s += binaryString.substring(i + 2, i + 4);
  154.           s += binaryString.substring(i, i + 2) + " ";
  155.           i += 8;
  156.         }
  157.  
  158.         p.appendChild(document.createTextNode(s));
  159.         p.appendChild(document.createElement("br"));
  160.       }
  161.  
  162.       bodyNode.appendChild(p);
  163.  
  164.       //
  165.       // Show binary data in bytes format.
  166.       //
  167.       p = document.createElement("p");
  168.       p.style.fontFamily = normalFont;
  169.       p.appendChild(document.createTextNode(bytesFormatString));
  170.       bodyNode.appendChild(p);
  171.  
  172.       // Must use fixed-width font for binary data.
  173.       p = document.createElement("p");
  174.       p.style.fontFamily = fixedWidthFont;
  175.     
  176.       i = 0;
  177.       j = 0;
  178.  
  179.       // Each character in binaryString is a hex (16-based) representation of
  180.       // 4 binary bits. So it takes 2 characters in binaryString to form a
  181.       // complete byte.
  182.       while (i < binaryString.length) {
  183.         translatedString = "";
  184.         // 2 characters in binaryString to form a byte
  185.         s = (i / 2).toString(16);   // to hex representation.
  186.  
  187.         // Prefix with '0' until its length is 4.
  188.         while (s.length < 4) {
  189.           s = "0" + s;
  190.         }
  191.         s += ": ";
  192.  
  193.         // Show 8 bytes per line
  194.         for (j = 0; j < 8; j++) {
  195.           tempS = binaryString.substring(i, i + 2); // 2 for 1 byte
  196.           i += 2;
  197.           s += tempS + " ";
  198.  
  199.           // Treat tempS as hex integer
  200.           charCode = parseInt(tempS, 16);
  201.           if (charCode < 32) {
  202.             translatedString += ".";
  203.           } else {
  204.             translatedString += String.fromCharCode(charCode);
  205.           }
  206.         }
  207.  
  208.         while (s.length < 32) {
  209.           s += " ";
  210.         }
  211.         s += translatedString;
  212.         
  213.         p.appendChild(document.createTextNode(s));
  214.         p.appendChild(document.createElement("br"));
  215.       }
  216.  
  217.       bodyNode.appendChild(p);
  218.     }
  219.   ]]>
  220.   </script>
  221. </head>
  222.  
  223. <!-- Test whether there is binary data -->
  224. <xsl:choose>
  225. <xsl:when test="descendant::*[contains(local-name(), 'Binary')]">
  226.   <!-- _locID_text="BinaryDataCaption" _locComment="Caption for Binary Data" -->
  227.   <xsl:variable name="BinaryDataCaption">Binary data:</xsl:variable>
  228.   <xsl:variable name="BinaryData"><xsl:value-of select="descendant::*[contains(local-name(), 'Binary')]"/></xsl:variable>
  229.   <body id="body" onload="window.fullyLoaded='true'; ToggleSystemElement(); ProcessBinaryData('{$BinaryData}', '{$BinaryDataCaption}', '{$WordsFormat}', '{$BytesFormat}', '{$FontFamily}', '{$FontFamily_FixWidth}')">
  230.     <xsl:for-each select="node()">
  231.       <!-- Treat EventData specially -->
  232.       <xsl:choose>
  233.         <xsl:when test="name()='EventData'">
  234.           <xsl:call-template name="EventDataNode"/>
  235.         </xsl:when>
  236.         <xsl:otherwise>
  237.           <xsl:call-template name="node"/>
  238.         </xsl:otherwise>
  239.       </xsl:choose>
  240.     </xsl:for-each>
  241.   </body>
  242. </xsl:when>
  243. <xsl:otherwise>  <!-- No binary data -->
  244.   <body id="body" onload="window.fullyLoaded=true;ToggleSystemElement();">
  245.     <xsl:for-each select="node()">
  246.       <!-- Treat EventData specially -->
  247.       <xsl:choose>
  248.         <xsl:when test="name()='EventData'">
  249.           <xsl:call-template name="EventDataNode"/>
  250.         </xsl:when>
  251.         <xsl:otherwise>
  252.           <xsl:call-template name="node"/>
  253.         </xsl:otherwise>
  254.       </xsl:choose>
  255.     </xsl:for-each>
  256.   </body>
  257. </xsl:otherwise>
  258. </xsl:choose>
  259.  
  260. </html>
  261. </xsl:template>
  262.  
  263. <xsl:template name="node">
  264.  
  265. <!-- Is this a "pure" text node like the "inner text" inside "<node>inner text</node>"? -->
  266. <xsl:choose>
  267. <xsl:when test="count(node())=0 and string-length(.) and not(name())">
  268. <table border="0" cellspacing="0">
  269.   <tr>
  270.     <td width="{$SignColumnWidth}" nowrap="true"></td>
  271.     <td style="{$FontStyle} {$VerticalAlignStyle}">
  272.       <xsl:value-of select="."/>
  273.     </td>
  274.   </tr>
  275. </table>
  276. </xsl:when>
  277. <xsl:otherwise>
  278. <!-- Not a pure text node-->
  279.  
  280. <xsl:choose>
  281.   <!-- Does this node contains attributes? -->
  282.   <xsl:when test="count(./@*)">
  283.     <!-- Yes, contains attributes, we need to make it collapsable -->
  284.  
  285.     <xsl:choose>
  286.  
  287.       <!-- Does this node contains only text like "<node>inner text</node>"? -->
  288.       <xsl:when test="count(node())=1 and text()">
  289.         <!-- Yes, only inner text -->
  290.         <table onClick="Toggle(this)" style="cursor: hand;">
  291.           <tr>
  292.             <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$SignColumnWidth}" nowrap="true">
  293.               <b>-</b>
  294.             </td>
  295.             <xsl:text>    </xsl:text>
  296.             <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$ElementNameColumnWidth}" nowrap="true">
  297.               <b>
  298.                 <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="name()"/>
  299.               </b>
  300.             </td>
  301.             <td style="{$FontStyle} {$VerticalAlignStyle}">
  302.               <xsl:value-of select="text()"/>
  303.             </td>
  304.           </tr>
  305.         </table>
  306.         <div>
  307.           <!-- This div will be hided upon handling the above "onclick" event -->
  308.           <xsl:for-each select="./@*">
  309.             <table border="0" cellspacing="0">
  310.               <tr>
  311.                 <td width="{$SignColumnWidth}" nowrap="true"></td>
  312.                 <td width="{$SignColumnWidth}" nowrap="true"></td>
  313.                 <!-- We do need 2 sign widths for nice formatting -->
  314.                 <td width="{$AttributeIndent}" nowrap="true"></td>
  315.                 <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$AttributeNameColumnWidth}" nowrap="true">
  316.                   [ <b>
  317.                     <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="name()"/>
  318.                   </b>]
  319.                 </td>
  320.                 <td style="{$FontStyle} {$VerticalAlignStyle}">
  321.                   <xsl:value-of select="."/>
  322.                 </td>
  323.               </tr>
  324.             </table>
  325.           </xsl:for-each>
  326.         </div>
  327.       </xsl:when>
  328.       <xsl:otherwise>
  329.         <!-- Not "only inner text -->
  330.         <table onClick="Toggle(this)" style="cursor: hand;">
  331.           <tr>
  332.             <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$SignColumnWidth}" nowrap="true">
  333.               <b>-</b>
  334.             </td>
  335.             <xsl:text>    </xsl:text>
  336.             <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$ElementNameColumnWidth}" nowrap="true">
  337.               <b>
  338.                 <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="name()"/>
  339.               </b>
  340.             </td>
  341.           </tr>
  342.         </table>
  343.         <div>
  344.           <!-- Deal with attributes -->
  345.           <xsl:for-each select="./@*">
  346.             <table border="0" cellspacing="0">
  347.               <tr>
  348.                 <td width="{$SignColumnWidth}" nowrap="true"></td>
  349.                 <td width="{$SignColumnWidth}" nowrap="true"></td>
  350.                 <!-- We do need 2 sign widths for nice formatting -->
  351.                 <td width="{$AttributeIndent}" nowrap="true"></td>
  352.                 <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$AttributeNameColumnWidth}" nowrap="true">
  353.                   [ <b>
  354.                     <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="name()"/>
  355.                   </b>]
  356.                 </td>
  357.                 <td style="{$FontStyle} {$VerticalAlignStyle}">
  358.                   <xsl:value-of select="."/>
  359.                 </td>
  360.               </tr>
  361.             </table>
  362.           </xsl:for-each>
  363.  
  364.           <!-- Deal with sub-nodes -->
  365.           <xsl:for-each select="node()">
  366.             <table border="0" cellspacing="0">
  367.               <tr>
  368.                 <td width="{$SignColumnWidth}" nowrap="true"></td>
  369.                 <td width="{$indent}" nowrap="true"></td>
  370.                 <td style="{$FontStyle} {$VerticalAlignStyle}">
  371.                   <xsl:call-template name="node"/>
  372.                 </td>
  373.               </tr>
  374.             </table>
  375.           </xsl:for-each>
  376.         </div>
  377.       </xsl:otherwise>
  378.     </xsl:choose>
  379.  
  380.   </xsl:when>
  381.   <xsl:otherwise>
  382.     <!-- Contains no attributes. Whether to be collapsable depends on whether it has children. -->
  383.     <!-- Does this node contains only text like "<node>inner text</node>"? -->
  384.     <xsl:choose>
  385.       <xsl:when test="count(node())=1 and text()">
  386.         <!-- Only has inner text -->
  387.         <table>
  388.           <tr>
  389.             <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$SignColumnWidth}" nowrap="true"></td>
  390.             <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$ElementNameColumnWidth}" nowrap="true">
  391.               <b>
  392.                 <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="name()"/>
  393.               </b>
  394.             </td>
  395.             <td style="{$FontStyle} {$VerticalAlignStyle}">
  396.               <xsl:value-of select="text()"/>
  397.             </td>
  398.           </tr>
  399.         </table>
  400.       </xsl:when>
  401.       <xsl:otherwise>
  402.         <!-- Not "only inner text" -->
  403.  
  404.         <!-- Does this node have children? -->
  405.         <xsl:choose>
  406.           <xsl:when test="count(node())">
  407.             <table onClick="Toggle(this)" style="cursor: hand;">
  408.               <tr>
  409.                 <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$SignColumnWidth}" nowrap="true">
  410.                   <b>-</b>
  411.                 </td>
  412.                 <xsl:text>    </xsl:text>
  413.                 <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$ElementNameColumnWidth}" nowrap="true">
  414.                   <b>
  415.                     <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="name()"/>
  416.                   </b>
  417.                 </td>
  418.               </tr>
  419.             </table>
  420.             <div>
  421.               <xsl:for-each select="node()">
  422.                 <table border="0" cellspacing="0">
  423.                   <tr>
  424.                     <td width="{$SignColumnWidth}" nowrap="true"></td>
  425.                     <td width="{$indent}" nowrap="true"></td>
  426.                     <td style="{$FontStyle} {$VerticalAlignStyle}">
  427.                       <xsl:call-template name="node"/>
  428.                     </td>
  429.                   </tr>
  430.                 </table>
  431.               </xsl:for-each>
  432.             </div>
  433.           </xsl:when>
  434.           <xsl:otherwise>
  435.             <!-- No children -->
  436.             <table>
  437.               <tr>
  438.                 <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$SignColumnWidth}" nowrap="true"></td>
  439.                 <td style="{$FontStyle}">
  440.                   <b>
  441.                     <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="name()"/>
  442.                   </b>
  443.                 </td>
  444.               </tr>
  445.             </table>
  446.           </xsl:otherwise>
  447.         </xsl:choose>
  448.       </xsl:otherwise>
  449.     </xsl:choose>
  450.  
  451.   </xsl:otherwise>
  452. </xsl:choose>
  453.  
  454. </xsl:otherwise>
  455. </xsl:choose>
  456. </xsl:template>
  457.  
  458. <!-- Template for "EventData". This is used for "System\EventData" only. -->
  459. <xsl:template name="EventDataNode">
  460.   <!-- Does this node have children? -->
  461.   <xsl:choose>
  462.     <xsl:when test="count(node())">
  463.       <table onClick="Toggle(this)" style="cursor: hand;">
  464.         <tr>
  465.           <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$SignColumnWidth}" nowrap="true">
  466.             <b>-</b>
  467.           </td>
  468.           <!-- &#  is tab -->
  469.           <xsl:text>    </xsl:text>
  470.           <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$ElementNameColumnWidth}" nowrap="true">
  471.             <b>
  472.               <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="name()"/>
  473.             </b>
  474.           </td>
  475.         </tr>
  476.       </table>
  477.       <div>
  478.         <xsl:for-each select="node()">
  479.           <table border="0" cellspacing="0">
  480.             <tr>
  481.               <td width="{$SignColumnWidth}" nowrap="true"></td>
  482.               <td width="{$indent}" nowrap="true"></td>
  483.               <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$ElementNameColumnWidth}" nowrap="true">
  484.                 <b>
  485.                   <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="./@Name"/>
  486.                 </b>
  487.               </td>
  488.               <td style="{$FontStyle} {$VerticalAlignStyle}">
  489.                 <xsl:value-of select="text()"/>
  490.               </td>
  491.             </tr>
  492.           </table>
  493.         </xsl:for-each>
  494.       </div>
  495.     </xsl:when>
  496.     <xsl:otherwise>
  497.       <!-- No children -->
  498.       <table>
  499.         <tr>
  500.           <td style="{$FontStyle} {$VerticalAlignStyle}" width="{$SignColumnWidth}" nowrap="true"></td>
  501.           <td style="{$FontStyle}">
  502.             <b>
  503.               <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="name()"/>
  504.             </b>
  505.           </td>
  506.         </tr>
  507.       </table>
  508.     </xsl:otherwise>
  509.   </xsl:choose>
  510. </xsl:template>  
  511.  
  512. </xsl:stylesheet>
  513.