I'm working on a little XML/XSLT project and I'm having trouble retrieving more than one element from the XML file.
I want to retrieve the client name(Attribute) and the transaction amount(Attribute) but it doesn't work. The only element attribute I can output is client name
.
I've tried to change <xsl:template match="client">
to <xsl:template match="list">
but then everything was showing and I don't want the question element to print.
Once names and amounts will output, I need to sum the amounts to show the total but first I really need to get the amounts to output. Any idea?
XML File :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet href="xslt.xml"
type="application/xml"?>
<list>
<client name="Morton">
<transaction amount="43" />
<question>Who?</question>
<transaction amount="21" />
</client>
<client name="Mingus">
<transaction amount="6" />
<transaction amount="32" />
<question>Where?</question>
<transaction amount="45" />
</client>
</list>
XSLT File :
<?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="client">
<html>
<body>
<p>Name:</p>
<xsl:apply-templates select="client" />
<xsl:value-of select="client" />
<xsl:value-of select="@name" />
<p>Total:</p>
<xsl:value-of select="transaction" />
<xsl:value-of select="@amount" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Current Output Result:
Client:
Morton
Total:
Client:
Mingus
Total:
Desired Output Result:
Client: Morton
Total: 64
Client: Mingus
Total: 83