Jump to content

2 XML issues


Guest FirefoxRocks

Recommended Posts

Guest FirefoxRocks

I am developing some XML that requires elements to be sorted.First issue: Sorting by multiple elementsI need to sort the data by points, then goals. So for example:4 goals/1 assist comes before 3 goals/2 assists which comes before 2 goals/3 assists. All of them have 5 points, but it is sorted by goals after it has been sorted by points.How do I do this with <xsl:sort/>? I already have <xsl:sort select="points"/>, so how do I put the other condition in?Second issue: Auto-numbering the listOnce I have everything sorted, I would like to auto-number the list starting with 1 for the first person. How do I do this with JavaScript/XSLT?Also, people with the same points have the same rank.If you look at this MSHTML page (not created by me), you'll see what I am trying to do with XML: http://muskie.rrdsb.com/ffhs/hockey/htdocs/norwossa.php (player statistics table)

Link to comment
Share on other sites

For your first issue, add another xsl:sort element for the second sorting key.For the second issue, I think if you can use an <ol> it would be the easiest. If not, then... hmm... position()? No... that would probably show you the source position. Perhaps if you can do a second XSLT transformation, you can then output the position of each row in a new cell within the row.

Link to comment
Share on other sites

Guest FirefoxRocks

Ok, first issue was easier than I thought.Now as for the second issue, what do I do for a second XSLT transformation and how do I do it?

Link to comment
Share on other sites

Guest FirefoxRocks

So far the JavaScript is working, I have this:

<script type="text/javascript">	//<![CDATA[	function rank() {		var table = document.getElementById('stats');		var rows = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr');				var i;				for(i=0; i<rows.length; i++) {			rows[i].getElementsByTagName("th")[0].innerHTML = i+1;		}	}	//]]></script>

The only issue is that if 2 people have the same points, they should have the same rank, obviously the script here doesn't do that. Is there a way for that to work?

Link to comment
Share on other sites

Don't you have PHP? If you do, you can do it (the second XSLT tranformation that is) from there.As for the rank, that's a new one... hmm... well, based on your java script:

		var e = 0;		for(i=0; i<rows.length; i++) {			rows[i].getElementsByTagName("th")[0].innerHTML = ++e;			if (e == rows[e].getElementsByTagName("th")[0].innerHTML) --e;		}

However, if I follow the sample you gave, I'm guessing your next request will be to have "st", "nd", "rd" and "th", right? Well... I'd do them within the second XSLT transformation (PHP agian), but if you're going to stick with the JS method, you're going to have to use a few more if statements on the "e".

Link to comment
Share on other sites

Guest FirefoxRocks

I modified your JavaScript a little, yours gave errors on the if line for some reason, even when I added curly brackets.

//editdocument.write("The code didn't work!");

However, if I follow the sample you gave, I'm guessing your next request will be to have "st", "nd", "rd" and "th", right?
No, it should remain as an integer value. You are looking at the wrong table, you need to look at the second one, the big one.There is one problem with my JavaScript though, it doesn't jump numbers when several people have the same rank.For example, this is the desired result:1,2,3,3,3,6,7With the above code, it outputs:1,2,3,3,3,4,5How do I get it to output the row number if the people do not have the same points/rank?
Link to comment
Share on other sites

How did you modified my code to make it work exactly? Removed the "if" line altogether?Anyway, it's a little late where I live now, so I can't think of a solution, but just of curiosity, why? If you have more than one person being at 3rd place, isn't technically speaking the next one 4th?

Link to comment
Share on other sites

Guest FirefoxRocks
function rank() {	var table = document.getElementById('stats');	var rows = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr');	var i;	for(i=0; i<rows.length; i++) {		if(i>0) {						j = i-1; // previous row counter						if (rows[i].getElementsByTagName("td")[4].innerHTML == rows[j].getElementsByTagName("td")[4].innerHTML) {				rows[i].getElementsByTagName("th")[0].innerHTML == rows[j].getElementsByTagName("th")[0].innerHTML;			}			else {				rows[i].getElementsByTagName("th")[0].innerHTML = i;			}		}		else if(i==0) {			rows[i].getElementsByTagName("th")[0].innerHTML = i+1;		}	}}

THAT WORKS!!!! Except if there are multiple people at the same rank, all shows no number at all.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...