title: reformat an xml file
body: <p>I have the following xml file:    </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;Data xmlns="http://www.test.com"&gt;
          &lt;form Name="Group1"&gt;
              &lt;Period Time="19042016T08:35:00"/&gt;
              &lt;Type c="1"&gt;Load&lt;/Type&gt;
              &lt;Type c="2"&gt;Memory&lt;/Type&gt;
              &lt;Type c="3"&gt;CPU&lt;/Type&gt;
              &lt;Type c="4"&gt;Task&lt;/Type&gt;
              &lt;Value Item="M-1"&gt;
                  &lt;val c="1"&gt;2979&lt;/val&gt;
                  &lt;val c="2"&gt;0&lt;/val&gt;
                  &lt;val c="3"&gt;9599&lt;/val&gt;
                  &lt;val c="4"&gt;0&lt;/val&gt;
              &lt;/Value&gt;
              &lt;Value Item="M-2"&gt;
                  &lt;val c="1"&gt;2973&lt;/val&gt;
                  &lt;val c="2"&gt;0&lt;/val&gt;
                  &lt;val c="3"&gt;0&lt;/val&gt;
                  &lt;val c="4"&gt;0&lt;/val&gt;
              &lt;/Value&gt;
              &lt;Value Item="M-3"&gt;
                  &lt;val c="1"&gt;2985&lt;/val&gt;
                  &lt;val c="2"&gt;11889&lt;/val&gt;
                  &lt;val c="3"&gt;0&lt;/val&gt;
                  &lt;val c="4"&gt;0&lt;/val&gt;
              &lt;/Value&gt;
              &lt;Value Item="M-4"&gt;
                  &lt;val c="1"&gt;28&lt;/val&gt;
                  &lt;val c="2"&gt;0&lt;/val&gt;
                  &lt;val c="3"&gt;0&lt;/val&gt;
                  &lt;val c="4"&gt;2980&lt;/val&gt;
              &lt;/Value&gt;
          &lt;/form&gt;
          &lt;form Name="Group2"&gt;
              &lt;Period Time="19042016T08:35:00"/&gt;
              &lt;Type c="1"&gt;Process&lt;/Type&gt;
              &lt;Type c="2"&gt;User&lt;/Type&gt;
              &lt;Type c="3"&gt;command&lt;/Type&gt;
              &lt;Type c="4"&gt;priority&lt;/Type&gt;
              &lt;Value Item="M-1"&gt;
                  &lt;val c="1"&gt;0&lt;/val&gt;
                  &lt;val c="2"&gt;0&lt;/val&gt;
                  &lt;val c="3"&gt;0&lt;/val&gt;
                  &lt;val c="4"&gt;4477&lt;/val&gt;
              &lt;/Value&gt;
              &lt;Value Item="M-2"&gt;
                  &lt;val c="1"&gt;0&lt;/val&gt;
                  &lt;val c="2"&gt;0&lt;/val&gt;
                  &lt;val c="3"&gt;0&lt;/val&gt;
                  &lt;val c="4"&gt;4540&lt;/val&gt;
              &lt;/Value&gt;
              &lt;Value Item="M-3"&gt;
                  &lt;val c="1"&gt;0&lt;/val&gt;
                  &lt;val c="2"&gt;0&lt;/val&gt;
                  &lt;val c="3"&gt;0&lt;/val&gt;
                  &lt;val c="4"&gt;4526&lt;/val&gt;
              &lt;/Value&gt;
              &lt;Value Item="M-4"&gt;
                  &lt;val c="1"&gt;0&lt;/val&gt;
                  &lt;val c="2"&gt;0&lt;/val&gt;
                  &lt;val c="3"&gt;0&lt;/val&gt;
                  &lt;val c="4"&gt;4445&lt;/val&gt;
              &lt;/Value&gt;
          &lt;/form&gt;
      &lt;/Data&gt;
  </code></pre>
  
  <p>And I would like to have an output as follows:    </p>
  
  <pre><code>Group=Group1, Time=19042016T08:35:00    
               M-1        M-2         M-3         M-4     
  Load        2979       2973        2985          28
  Memory         0          0       11889           0
  CPU         9599          0           0           0
  Task           0          0           0        2980
  
  Name=Group2, Time=19042016T08:35:00    
               M-1        M-2         M-3         M-4     
  Process        0          0           0           0
  User           0          0           0           0
  command        0          0           0           0
  priority    4477       4540        4445        4445  
  </code></pre>
  
  <p>By looking at some xsltproc examples as suggested here. I came up with the following stylesheet.    </p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;xsl:stylesheet version="1.0" 
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  xmlns:t="http://www.test.com"&gt;
      &lt;xsl:output method="text"/&gt;
      &lt;xsl:strip-space elements="*"/&gt;
      &lt;xsl:template match="/t:Data"&gt;
          &lt;xsl:for-each select="t:form"&gt;
              &lt;xsl:value-of select="concat('Group=', @Name, ', Time=',t:Period/@Time,'&amp;#xA;')"/&gt;
              &lt;xsl:for-each select="t:Type"&gt;
                  &lt;xsl:value-of select="concat('CounterName=', text(), '&amp;#xA;')"/&gt;
              &lt;/xsl:for-each&gt;
              &lt;xsl:for-each select="t:Value"&gt;
                  &lt;xsl:value-of select="concat('Machine=', @Item, '&amp;#xA;')"/&gt;
                  &lt;xsl:for-each select="t:val"&gt;
                      &lt;xsl:value-of select="concat('CounterValue=', text(), '&amp;#xA;')"/&gt;
                  &lt;/xsl:for-each&gt;
              &lt;/xsl:for-each&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Then the result is as follows:    </p>
  
  <pre><code>xsltproc.exe tx.xsl data.xml 
  Group=Group1, Time=19042016T08:35:00
  CounterName=Load
  CounterName=Memory
  CounterName=CPU
  CounterName=Task
  Machine=M-1
  CounterValue=2979
  CounterValue=0
  CounterValue=9599
  CounterValue=0
  Machine=M-2
  CounterValue=2973
  CounterValue=0
  CounterValue=0
  CounterValue=0
  Machine=M-3
  CounterValue=2985
  CounterValue=11889
  CounterValue=0
  CounterValue=0
  Machine=M-4
  CounterValue=28
  CounterValue=0
  CounterValue=0
  CounterValue=2980
  Group=Group2, Time=19042016T08:35:00
  CounterName=Process
  CounterName=User
  CounterName=command
  CounterName=priority
  Machine=M-1
  CounterValue=0
  CounterValue=0
  CounterValue=0
  CounterValue=4477
  Machine=M-2
  CounterValue=0
  CounterValue=0
  CounterValue=0
  CounterValue=4540
  Machine=M-3
  CounterValue=0
  CounterValue=0
  CounterValue=0
  CounterValue=4526
  Machine=M-4
  CounterValue=0
  CounterValue=0
  CounterValue=0
  CounterValue=4445
  </code></pre>
  
  <p>Does anyone have an idea how I can get from the result of the xsltproc to the desired output above. Can it be done with a different stylesheet or I will need a post-processing script to be applied after the result of the current stylesheet?</p>
  
  <p>Thanks so much in advance.</p>