Hello everybody, I have a problem to sort data in XML, when added to a variable of another XML.
It works like this:
I have two XML, the first has the name and the score of a person, and the second has the name and a extra score.
I've got to build a table of data, even with the extra added to the score.
What was I could not even sort my table by this new score.
Below is the XML:
acc.xml
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="example.xsl"?>
<acc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<person>
<name>Beto Almeida</name>
<score>15</score>
</person>
<person>
<name>Adriano Fraporti</name>
<score>5</score>
</person>
<person>
<name>Caetano Paiva</name>
<score>5</score>
</person>
<person>
<name>Francisco Junior</name>
<score>15</score>
</person>
<person>
<name>Natalia Perez</name>
<score>15</score>
</person>
<person>
<name>Ivan Castrolebre</name>
<score>30</score>
</person>
</acc>
add.xml
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<add xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<person>
<name>Beto Almeida</name>
<score>4</score>
</person>
<person>
<name>Adriano Fraporti</name>
<score>22</score>
</person>
<person>
<name>Caetano Paiva</name>
<score>7</score>
</person>
<person>
<name>Francisco Junior</name>
<score>2</score>
</person>
<person>
<name>Natalia Perez</name>
<score>33</score>
</person>
<person>
<name>Ivan Castrolebre</name>
<score>1</score>
</person>
</add>
Below is the XSL:
example.xsl
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="acc">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Untitled Document</title>
</head>
<body>
<table width="100%" bgcolor="#909090" border="0" align="left">
<tr>
<td align="left" width="120"><strong>Name</strong></td>
<td align="center" width="120" ><strong>Score</strong></td>
<td align="center" width="120" ><strong>Add</strong></td>
<td align="center" width="120" ><strong>New Score</strong></td>
</tr>
</table>
<xsl:for-each select="person">
<xsl:sort select="score" order="descending" data-type="number"/>
<xsl:variable name="varname" select="name"/>
<xsl:variable name="varadd" select="document('add.xml')/add/person[name=$varname]/score"/>
<xsl:variable name="varnewscore" select="score+$varadd"/>
<table width="100%" bgcolor="#C0C0C0" border="0" align="left">
<tr>
<td align="left" width="120"> <xsl:value-of select="name"/> </td>
<td align="center" width="120" > <xsl:value-of select="score"/> </td>
<td align="center" width="120" ><xsl:value-of select="$varadd"/></td>
<td align="center" width="120" ><xsl:value-of select="$varnewscore"/></td>
</tr>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Take a Look
So, anyone know how to sort those values by the column "New Scores"?
thank you now, and sorry for bad english.