Click to See Complete Forum and Search --> : Addition in XML


Araunah
01-05-2007, 03:47 PM
I have been making something else for myself. I am trying to add all the numbers together to get a total.

XSL Stylesheet

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match='/'>
<html>
<body bgcolor='#000000'>
<span style='font-size: 13px; color: #FF0000; font-face: georgia;'>
<xsl:value-of select="Deck/Faction"/> <xsl:value-of select="Deck/Class"/></span><br/>
<span style='font-size: 11px; color: #FFFFFF; font-face: georgia;'>

<b>Allies</b><br/>
<table cellpadding='2' cellspacing='0' border='0' style='border: solid 1px #FF0000; color: #FFFFFF; font-size: 10px;'>
<xsl:for-each select="Deck/Main_Deck/Allies/Card">
<xsl:sort select="Number"/>
<tr>
<td style='border: solid 1px #FF0000;'><xsl:value-of select="Name"/></td>
<td style='border: solid 1px #FF0000;'><xsl:value-of select="Rarity"/></td>
<td style='border: solid 1px #FF0000;'><xsl:value-of select="Number"/></td>
</tr>
</xsl:for-each>
</table>
<b>Equiptment</b><br/>
<table cellpadding='2' cellspacing='0' border='0' style='border: solid 1px #FF0000; color: #FFFFFF; font-size: 10px;'>
<xsl:for-each select="Deck/Main_Deck/Equiptment/Card">
<xsl:sort select="Number"/>
<tr>
<td style='border: solid 1px #FF0000;'><xsl:value-of select="Name"/></td>
<td style='border: solid 1px #FF0000;'><xsl:value-of select="Rarity"/></td>
<td style='border: solid 1px #FF0000;'><xsl:value-of select="Number"/></td>
</tr>
</xsl:for-each>
</table>
<b>Quests</b><br/>
<table cellpadding='2' cellspacing='0' border='0' style='border: solid 1px #FF0000; color: #FFFFFF; font-size: 10px;'>
<xsl:for-each select="Deck/Main_Deck/Quest/Card">
<xsl:sort select="Number"/>
<tr>
<td style='border: solid 1px #FF0000;'><xsl:value-of select="Name"/></td>
<td style='border: solid 1px #FF0000;'><xsl:value-of select="Rarity"/></td>
<td style='border: solid 1px #FF0000;'><xsl:value-of select="Number"/></td>
</tr>
</xsl:for-each>
</table>
Total
<xsl:value-of select="//Number + //Number"/>
// I tried using a For-each but no luck

</span>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="Warrior Deck.xsl"?>
<Deck>
<Faction>Horde</Faction>
<Class>Warrior</Class>
<Hero>Gorebelly</Hero>
<Main_Deck>
<Allies>
<Card>
<Name>Taz&apos;dingo</Name>
<Rarity>Common</Rarity>
<Number>3</Number>
</Card>
<Card>
<Name>Veshral</Name>
<Rarity>Common</Rarity>
<Number>3</Number>
</Card>
<Card>
<Name>Thunderhead Hippogryph</Name>
<Rarity>Rare</Rarity>
<Number>3</Number>
</Card>
<Card>
<Name>Zy&apos;lah Manslayer</Name>
<Rarity>Rare</Rarity>
<Number>3</Number>
</Card>
<Card>
<Name>Zygore Bladebreaker</Name>
<Rarity>Common</Rarity>
<Number>3</Number>
</Card>
</Allies>
<Equiptment>
<Card>
<Name>Annihilator</Name>
<Rarity>Uncommon</Rarity>
<Number>4</Number>
</Card>
<Card>
<Name>Golem Skull Helm</Name>
<Rarity>Uncommon</Rarity>
<Number>4</Number>
</Card>
<Card>
<Name>Herod Shoulders</Name>
<Rarity>Rare</Rarity>
<Number>2</Number>
</Card>
<Card>
<Name>Krol Blade</Name>
<Rarity>Uncommon</Rarity>
<Number>3</Number>
</Card>
<Card>
<Name>StrongHold Gauntlets</Name>
<Rarity>Epic</Rarity>
<Number>2</Number>
</Card>
</Equiptment>
<Quest>
<Card>
<Name>Chasing A-Me01</Name>
<Rarity>Common</Rarity>
<Number>3</Number>
</Card>
<Card>
<Name>Torek's Assault</Name>
<Rarity>Uncommon</Rarity>
<Number>4</Number>
</Card>
<Card>
<Name>Counter Attack</Name>
<Rarity>Uncommon</Rarity>
<Number>4</Number>
</Card>
<Card>
<Name>Your Fortune Awaits You</Name>
<Rarity>Common</Rarity>
<Number>4</Number>
</Card>
<Card>
<Name>For The Horde!</Name>
<Rarity>Uncommon</Rarity>
<Number>1</Number>
</Card>
</Quest>
</Main_Deck>
<Side_Board>
<Allies>
<Card>
<Name>Confessor Mildred</Name>
<Rarity>Common</Rarity>
<Number>4</Number>
</Card>
</Allies>
</Side_Board>
</Deck>

Using the number field trying to add them all together to get a total.

And is there anyway to sort in decending order, instead of assending?

Araunah
01-05-2007, 03:51 PM
Also is there anyway to do "&amp;nbsp;" inside of XSL?

&nbsp; if the &amp; shows as the letters.

Charles
01-05-2007, 04:26 PM
See http://saxon.sourceforge.net/saxon6.5.5/expressions.html#NumericExpressions and http://saxon.sourceforge.net/saxon6.5.5/xsl-elements.html#xsl:sort .

Araunah
01-05-2007, 04:53 PM
both links are very helpful. I am still at a loss for how the numeric expression works. I understand that it's XPath, but I do not know how to properly format it in XSL inorder to have it display correctly. Sorry, I know this is a novice question. Thank you very much for your help though.

Charles
01-05-2007, 05:13 PM
See also http://saxon.sourceforge.net/saxon6.5.5/xsl-elements.html#xsl:value-of .