Click to See Complete Forum and Search --> : XML Child nodes into HTML page


adamdidthis
04-28-2009, 07:33 PM
Hi All,

First post but here goes.

Ok I have the following XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<STATS>
<TIME>0:57</TIME>
<HALF>First</HALF>
<PHASE>1</PHASE>
<GAMEID>HLDS12STMS1224042009</GAMEID>
<STAT>
<NAME>TEAM 1</NAME>
<VAL1>Highlanders</VAL1>
<VAL2>0</VAL2>
<VAL3>#121C46</VAL3>
<VAL4>#CC9933</VAL4>
</STAT>
<STAT>
<NAME>TEAM 2</NAME>
<VAL1>Stormers</VAL1>
<VAL2>0</VAL2>
<VAL3>#CCCCCC</VAL3>
<VAL4>#121C46</VAL4>
</STAT>
<STAT>
<NAME>POSSESSION</NAME>
<VAL1>69</VAL1>
<VAL2>31</VAL2>
</STAT>
<STAT>
<NAME>PASSES COMPLETED</NAME>
<VAL1>2</VAL1>
<VAL2>1</VAL2>
</STAT>
<STAT>
<NAME>SEASON KICK OFFS REGATHERED</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON TOTAL ERRORS</NAME>
<VAL1>0</VAL1>
<VAL2>3</VAL2>
</STAT>
<STAT>
<NAME>SEASON HANDLING ERRORS</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>PENALTIES CONCEDED</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>PICK AND GO</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON TACKLES MISSED</NAME>
<VAL1>0</VAL1>
<VAL2>3</VAL2>
</STAT>
<STAT>
<NAME>NOT STRAIGHT</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON TRIES</NAME>
<VAL1>7</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON KICKS IN PLAY</NAME>
<VAL1>3</VAL1>
<VAL2>3</VAL2>
</STAT>
<STAT>
<NAME>TRIES</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>AGAINST THROW</NAME>
<VAL1>2</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON PASSES COMPLETED</NAME>
<VAL1>2</VAL1>
<VAL2>1</VAL2>
</STAT>
<STAT>
<NAME>INTERCEPTS</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>TEAM ABREV</NAME>
<VAL1>HLD</VAL1>
<VAL2>STM</VAL2>
</STAT>
<STAT>
<NAME>ERRORS MADE</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON PENALTIES</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>LINE BREAKS</NAME>
<VAL1>1</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON TRIES AGAINST</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON RED CARDS</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON POINTS</NAME>
<VAL1>48</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>MINS IN OPP 22</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>TACKLES MISSED</NAME>
<VAL1>0</VAL1>
<VAL2>3</VAL2>
</STAT>
<STAT>
<NAME>SEASON TACKLES MADE</NAME>
<VAL1>0</VAL1>
<VAL2>3</VAL2>
</STAT>
<STAT>
<NAME>SEASON KICKING ERRORS</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>MINS IN POSSESSION</NAME>
<VAL1>1</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON YELLOW CARDS</NAME>
<VAL1>1</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>HANDLING ERRORS</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>TACKLES MADE</NAME>
<VAL1>0</VAL1>
<VAL2>3</VAL2>
</STAT>
<STAT>
<NAME>TERRITORY</NAME>
<VAL1>39</VAL1>
<VAL2>61</VAL2>
</STAT>
<STAT>
<NAME>FREE KICKS</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>BREAKDOWNS</NAME>
<VAL1>1</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SCRUMS WON</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SEASON ERRORS MADE</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>TURNOVERS CONCEDED</NAME>
<VAL1>2</VAL1>
<VAL2>2</VAL2>
</STAT>
<STAT>
<NAME>SEASON OFFLOADS</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>SHORT-ARM PENALTIES CONCEDED</NAME>
<VAL1>0</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>TEAMID</NAME>
<VAL1>HLDS12</VAL1>
<VAL2>STMS12</VAL2>
</STAT>
<STAT>
<NAME>TURNOVERS WON</NAME>
<VAL1>2</VAL1>
<VAL2>2</VAL2>
</STAT>
<STAT>
<NAME>LINEOUTS WON</NAME>
<VAL1>3</VAL1>
<VAL2>0</VAL2>
</STAT>
<STAT>
<NAME>BREAKDOWN TURNOVERS WON</NAME>
<VAL1>0</VAL1>
<VAL2>2</VAL2>
</STAT>
<JUMPERS_STAT>
<NAME>TEAM_1_JUMPERS</NAME>
<NAME1>4. BEKHUIS</NAME1>
<VAL1>3</VAL1>
<VAL11>2</VAL11>
<NAME2>5. DONNELLY</NAME2>
<VAL2>0</VAL2>
<VAL21>0</VAL21>
<NAME3>8. NAOUPU</NAME3>
<VAL3>0</VAL3>
<VAL31>0</VAL31>
</JUMPERS_STAT>
<JUMPERS_STAT>
<NAME>TEAM_2_JUMPERS</NAME>
<NAME1>4. LOBBERTS</NAME1>
<VAL1>0</VAL1>
<VAL11>0</VAL11>
<NAME2>5. FONDSE</NAME2>
<VAL2>0</VAL2>
<VAL21>0</VAL21>
<NAME3>8. WATSON</NAME3>
<VAL3>0</VAL3>
<VAL31>0</VAL31>
</JUMPERS_STAT>
<SCORING_STAT>
<KICKING_TOTAL>0</KICKING_TOTAL>
<NAME>TEAM_1_SCORING</NAME>
<KICKER_NAME>-</KICKER_NAME>
<KICKER_STAT>PEN-0/0 CON-0/0 DG-0/0</KICKER_STAT>
<NAME0>-</NAME0>
<VAL0>0</VAL0>
<NAME1>-</NAME1>
<VAL1>0</VAL1>
<NAME2>-</NAME2>
<VAL2>0</VAL2>
</SCORING_STAT>
<SCORING_STAT>
<KICKING_TOTAL>0</KICKING_TOTAL>
<NAME>TEAM_2_SCORING</NAME>
<KICKER_NAME>-</KICKER_NAME>
<KICKER_STAT>PEN-0/0 CON-0/0 DG-0/0</KICKER_STAT>
<NAME0>-</NAME0>
<VAL0>0</VAL0>
<NAME1>-</NAME1>
<VAL1>0</VAL1>
<NAME2>-</NAME2>
<VAL2>0</VAL2>
</SCORING_STAT>
</STATS>


As you can see most of the nodes are called STAT.

I have written some javascript that will get the child nodes of the first STAT node but can't work out how to get it to look at the rest.

Please help me oh wise ones.

Charles
04-29-2009, 05:18 AM
JavaScript is never a good solution for content. What server side tools do you have available? PERL? PHP?

adamdidthis
04-29-2009, 05:22 AM
Yep not my fave either, but you have to do what you have to do

Charles
04-29-2009, 05:23 AM
Then server the page as XML but supply a XSLT stylesheet that transforms it into HTML client side. See http://www.w3schools.com/xsl/ .

adamdidthis
04-29-2009, 05:29 AM
Ok here is the main reason for doing this.

I have one XML file and need 2 different ways of looking at it. so the question is it possible to pass the name of the XML style sheet through a link or url somehow as I can not find a way of setting it otherwise.

Charles
04-29-2009, 05:31 AM
Are you certain that you don't have any server side scripting available?

adamdidthis
04-29-2009, 05:31 AM
Yep, it's very limited.

Charles
04-29-2009, 06:29 AM
No scripting and limited scripting are two different things. What do you have available?

adamdidthis
04-29-2009, 06:31 AM
ok read limited as none

Charles
04-29-2009, 06:33 AM
Then perhaps this can't be done with the resources available, not easily but that's what you would expect. You'll need two copies of the XML file, each with a different XSL stylesheet linked. And consider switching hosts.

adamdidthis
04-29-2009, 06:36 AM
Lol if only it were that easy, the xml is outputted by software and I don't want ot to have the workload added too. what would you reccomend to use?

Charles
04-29-2009, 06:45 AM
Then I would write something in JScript, possibly using the Windows Scripting Host / WScript thinggy, that employs the MSXML parser to in turn apply your two XSLT stylesheets and generate the two finished HTML files. Or I would write a batch file that does the same thing with Apache's Xalan. If you know Java you could write something that employs Xalan. The idea is that you need to generate the two HTML files and then upload them. (And you can script the uploading if you really want to earn your geek creds.)