home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / WindowsServerTrial / server.iso / sources / install.wim / 1 / Windows / System32 / wbem / texttable.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2006-09-18  |  5.9 KB  |  181 lines

  1. <xsl:stylesheet  xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  2. <!-- Copyright (c) Microsoft Corporation.  All rights reserved. -->
  3.  
  4.   <xsl:script language="VBScript"><![CDATA[
  5. Option Explicit
  6. 'This stylesheet formats DMTF XML encoded CIM objects into a tabular
  7. 'format using carriage returns and space characters only.
  8. Dim sPXML
  9. Dim propname(128)
  10. Dim lenarr(128)
  11. Dim bN(128)
  12. Dim iLens
  13. Dim iLensMax
  14. Dim propvalue(2048, 128)
  15. Dim iRow
  16. iRow = -1 
  17. Dim iResultCount
  18. Function CountResults(n)
  19.     iResultCount = iResultCount + 1
  20. End Function
  21. Function PadIt(ilen)
  22.     Dim i
  23.     Dim pads
  24.     i = ilen + 2
  25.     pads = "                "
  26.     while (i > len(pads))
  27.     pads = pads & pads
  28.     wend
  29.     PadIt = Left(pads, i)
  30. End Function
  31. Function GotInstance()
  32.     iLensMax = iLens
  33.     iLens = 0
  34.     iRow = iRow + 1
  35. End Function
  36. Function GetValues(n)
  37.     Dim child, iNum, i, strType
  38.     If iRow = 0 Then
  39.         'this is the first row - set up the headers
  40.         propname(iLens) = Me.Attributes.GetNamedItem("NAME").Value
  41.     Else
  42.         If propname(iLens) <> Me.Attributes.GetNamedItem("NAME").Value Then
  43.             'This is going to be messy - Find it or add it on the end
  44.         End If
  45.     End If
  46.     If strcomp(Me.NodeName,"Property.Array",1) = 0 Then
  47.     if (Me.hasChildNodes) then
  48.         propvalue(iRow, iLens) = "{"
  49.         iNum = Me.FirstChild.ChildNodes.Length
  50.         i = 1
  51.         strType = Me.attributes.getNamedItem("TYPE").nodeValue
  52.         For each child in Me.FirstChild.ChildNodes
  53.             if (strType = "string") then
  54.                 propvalue(iRow, iLens) = propvalue(iRow, iLens) & """" & child.nodeTypedValue & """"
  55.             elseif (strType = "char16") then
  56.                 propvalue(iRow, iLens) = propvalue(iRow, iLens) & "'" & child.nodeTypedValue & "'"
  57.             else
  58.                 propvalue(iRow, iLens) = propvalue(iRow, iLens) & child.nodeTypedValue
  59.             end if
  60.             if (i <> iNum) then
  61.                    propvalue(iRow, iLens) = propvalue(iRow, iLens) & ", "
  62.             end if
  63.             i = i + 1
  64.         Next
  65.         propvalue(iRow, iLens) = propvalue(iRow, iLens) & "}"
  66.     end if
  67.     ElseIf strcomp(Me.NodeName,"Property.Reference",1) = 0 Then
  68.     dim valref, node, hostnode, localnamespace, namespacenode, keybindings, keybinding
  69.     for each valref in Me.selectNodes("VALUE.REFERENCE")
  70.         for each node in valref.selectNodes(".//NAMESPACEPATH")
  71.             set hostnode = node.selectsinglenode("HOST")
  72.             if not hostnode is nothing then
  73.                 propvalue(irow, ilens) = "\\" & hostnode.text
  74.             end if
  75.             set localnamespace = node.selectsinglenode("LOCALNAMESPACEPATH")
  76.             if not localnamespace is nothing then
  77.                 for each namespacenode in localnamespace.selectnodes("NAMESPACE")
  78.                     propvalue(irow,ilens) = propvalue(irow,ilens) & "\" & namespacenode.attributes.getNamedItem("NAME").nodeValue
  79.                 next
  80.             end if
  81.             propvalue(irow,ilens) = propvalue(irow,ilens) & ":"
  82.         next
  83.         for each node in valref.selectNodes(".//INSTANCENAME")
  84.             propvalue(irow,ilens) = propvalue(irow,ilens) & node.attributes.getNamedItem("CLASSNAME").nodevalue
  85.             set keybindings = node.selectnodes("KEYBINDING")
  86.             i = 0
  87.             for each keybinding in keybindings
  88.                 i = i + 1
  89.                 if (i = 1) then
  90.                     propvalue(irow,ilens) = propvalue(irow,ilens) & "." 
  91.                 end if
  92.                 propvalue(irow,ilens) = propvalue(irow,ilens) & keybinding.attributes.getnameditem("NAME").nodeValue & "=""" & _
  93.                     keybinding.selectsinglenode("KEYVALUE").text & """"
  94.                 if (i <> keybindings.length) then
  95.                     propvalue(irow,ilens) = propvalue(irow,ilens) & ","
  96.                 end if
  97.             next
  98.         next
  99.     next        
  100.     Else
  101.     propvalue(iRow, iLens) = replace(replace(Me.nodeTypedValue, vbCr, ""), vbLF, "")
  102.     End If
  103.     iLens = iLens + 1
  104. End Function
  105. Function DisplayValues(n)
  106.     Dim sT
  107.     Dim sV
  108.     Dim i
  109.     Dim j
  110.     Dim k
  111.     'Determine the column widths
  112.     'look at the column headers first
  113.     iLensMax = iLens
  114.     iLens = 0
  115.     iRow = iRow + 1
  116.     i = 0
  117.     While i < iLensMax
  118.         k = getlength(propname(i))
  119.         If k > lenarr(i) Then
  120.             lenarr(i) = k
  121.         End If
  122.         i = i + 1
  123.     Wend
  124.     'look at the values
  125.     i = 0
  126.     While i < iRow
  127.         j = 0
  128.         While j < iLensMax
  129.             k = getlength(propvalue(i, j))
  130.             If k > lenarr(j) Then
  131.                 lenarr(j) = k
  132.             End If
  133.             j = j + 1
  134.         Wend
  135.         i = i + 1
  136.     Wend
  137.     'set up the column headers
  138.     i = 0
  139.     While i < iLensMax
  140.         j = lenarr(i) - getlength(propname(i))
  141.         sT = sT & propname(i) & PadIt(j)
  142.         i = i + 1
  143.     Wend
  144.     i = 0
  145.     While i < iRow
  146.         j = 0
  147.         While j < iLensMax
  148.             k = lenarr(j) - getlength(propvalue(i, j))
  149.         if bN(j)= 1 then
  150.                 sV = sV & PadIt(k-2) & propvalue(i, j) & "  "
  151.         Else
  152.                 sV = sV & propvalue(i, j) & PadIt(k)
  153.         End If
  154.             j = j + 1
  155.         Wend
  156.         sV = sV & vbCrLf
  157.         i = i + 1
  158.     Wend
  159.     DisplayValues = sT & vbCrLf & sV
  160. End Function
  161. Function GetLength(str)
  162.     Dim i, ch
  163.     'we have to manually compute length
  164.     GetLength = 0
  165.     For i = 1 to len(str)
  166.         ch = ascw(mid(str,i,1))
  167.         if (ch > 255) or (ch < 0) then
  168.             GetLength = GetLength + 2    'assume two byte spaces
  169.         else
  170.             GetLength = GetLength + 1
  171.         end if
  172.     Next
  173. End Function
  174.  
  175.   ]]></xsl:script>
  176. <xsl:template match="/"><xsl:apply-templates select="//RESULTS"/><xsl:apply-templates select="//INSTANCE"/><xsl:eval no-entities="true" language="VBScript">DisplayValues(this)</xsl:eval></xsl:template>
  177. <xsl:template match="RESULTS"><xsl:eval no-entities="true" language="VBScript">CountResults(this)</xsl:eval></xsl:template>
  178. <xsl:template match="INSTANCE"><xsl:eval language="VBScript">GotInstance()</xsl:eval><xsl:apply-templates select="PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE"/></xsl:template>
  179. <xsl:template match="PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE"><xsl:eval no-entities="true" language="VBScript">GetValues(this)</xsl:eval></xsl:template>
  180. </xsl:stylesheet>
  181.