bladestonight has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to learn how to use a XSL stylesheet after creating my XML file with XML::twig, but I think my end desire is a little too complicated for a begineer. Perhaps the XML file should be reordered. Looking at it now I think condensing the elements into attributes instead of children of the node was probably a big mistake. I would like a fresh view on the following...

I have this xml file, which I am trying to generate a table in html format.

<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <Volumetrics> <VolumeReport Name="v_example.gri" Version="1.0"> <CellSize CellSizeX="500.000" CellSizeY="500.000" Refinement="10"> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>147977918</CumulativeVol> </CellSize> <CellSize CellSizeX="500.000" CellSizeY="500.000" Refinement="4"> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>147751938</CumulativeVol> </CellSize> <CellSize CellSizeX="1000.000" CellSizeY="1000.000" Refinement="10 +"> <runtime units="seconds">8</runtime> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>134856090</CumulativeVol> </CellSize> <CellSize CellSizeX="1000.000" CellSizeY="1000.000" Refinement="4" +> <runtime units="seconds">9</runtime> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>134324000</CumulativeVol> </CellSize> <VolumeReport Name="south.gri" Version="1.0"> <CellSize CellSizeX="10.000" CellSizeY="10.000" Refinement="4"> <runtime units="seconds">7</runtime> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>125970002642</CumulativeVol> </CellSize> </VolumeReport> <VolumeReport Name="v_example.gri" Version="2.0"> <CellSize CellSizeX="500.000" CellSizeY="500.000" Refinement="10"> <runtime units="seconds">12</runtime> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>147977918</CumulativeVol> </CellSize> <CellSize CellSizeX="500.000" CellSizeY="500.000" Refinement="4"> <runtime units="seconds">10</runtime> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>147751938</CumulativeVol> </CellSize> <CellSize CellSizeX="1000.000" CellSizeY="1000.000" Refinement="10 +"> <runtime units="seconds">8</runtime> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>134880540</CumulativeVol> </CellSize> <CellSize CellSizeX="1000.000" CellSizeY="1000.000" Refinement="4" +> <runtime units="seconds">10</runtime> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>134324000</CumulativeVol> </CellSize> <VolumeReport Name="south.gri" Version="2.0"> <CellSize CellSizeX="10.000" CellSizeY="10.000" Refinement="4"> <runtime units="seconds">8</runtime> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>125970002642</CumulativeVol> </CellSize> </VolumeReport> </Volumetrics>

I desire my html to be a number of tables on the webpage. There should be a new table for each @Name, and new header rows for each different @Version. The rows should be the different CellSize/@CellSizeX and CellSize/@CellSizeY and the columns should be made up of CellSize/@Refinement,runtime and CumulativeVol. I desire these tables:
v_example.griGrid Refinements
Version 15.5410
CellSize Runtime Volume Runtime Volume
(500.000,500.000) 10 147751938 12 147977918
(1000.000,1000.000) 10 134856090 8 134472204
v_example.griGrid Refinements
Version 16.0410
CellSize Runtime Volume Runtime Volume
(500.000,500.000) 10 147751938 12 147977918
(1000.000,1000.000) 10 134324000 8 134880540

south.griGrid Refinements
Version 15.5410
CellSize Runtime Volume Runtime Volume
(10.000,10.000) 6 125970002642
south.griGrid Refinements
Version 16.0410
CellSize Runtime Volume Runtime Volume
(10.000,10.000) 8 125970002642

My XSL stylesheet is a slightly modified example off the internet, it doesn't even get close to producing the above so I don't think it would be very useful to post it here.

Firstly, should I reorder my XML?

Secondly, is there a kind soul out there who could show me what my stylesheet should look like?

Replies are listed 'Best First'.
Re: XML to XHTML table
by Herkum (Parson) on Apr 26, 2007 at 19:38 UTC

    In reference to your using attributes, I would avoid doing that for anything that is supposed to be information. Why? Consistency. I would keep attributes to help define the object and child nodes to describe all the information that is used by the parent.

    Whatever way you chose be consistent, don't let yourself or others have to guess WHERE they are going to find the information. KNOW where the information is going to be.

    You can identify that this is a problem basically by looking at your XSL, if it is turning out to be very complicated, then you are probably doing something wrong.

      My problem with this is I what to group nodes by Name, Version, cellsize and refinement. So in the following the information which changes are refinement, runtime and CumulativeVol, could I get my desired output just by having?:
      <VolumeReport> <Name>v_example.gri</Name> <Version>1.0</Version> <Refinement>10</Refinement> <CellSize> <CellSizeX>500.000</CellSizeX> <CellSizeY>500.000</CellSizeY> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>147977918</CumulativeVol> </CellSize> </VolumeReport> <VolumeReport> <Name>v_example.gri</Name> <Version>1.0</Version> <Refinement>4</Refinement> <CellSize> <CellSizeX>500.000</CellSizeX> <CellSizeY>500.000</CellSizeY> <VolumeUnits id="m3">Cubic Metres</VolumeUnits> <CumulativeVol>147751938</CumulativeVol> </CellSize> <VolumeReport>
      Desired output:
      v_example.griGrid Refinements
      Version 15.5410
      CellSize Runtime Volume Runtime Volume
      (500.000,500.000) 10 147751938 12 147977918