I have the following XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.3ds.com/xsd/XPDMXML">
<xsl:output method="text" doctype-public="XSLT-compat" encoding="ISO-8859-1"/>
<xsl:template match="/">
<xsl:for-each select="/foo/bar/AAA[Owned/text()='1']">
<xsl:variable name="vOP">
<xsl:value-of select="./Instancing"/>
</xsl:variable>
<xsl:for-each select="/foo/bar/BBB[Owned[text()=$vOP]]">
<xsl:variable name="vTO">
<xsl:value-of select="./Instancing"/>
</xsl:variable>
<xsl:for-each select="/foo/bar/CCC[Owned[text()=$vTO]]">
<xsl:variable name="vIE">
<xsl:value-of select="./Instancing"/>
</xsl:variable>
<xsl:text>"COUNT": </xsl:text><xsl:value-of select="count(/foo/buzz/DDD[Owned[text()=$vIE]])"/><xsl:text>,</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This is a sample input
<?xml version='1.0' encoding='utf-8'?>
<foo>
<bar>
<AAA>
<Owned>1</Owned>
<Instancing>2</Instancing>
</AAA>
<BBB>
<Owned>2</Owned>
<Instancing>3</Instancing>
</BBB>
<CCC>
<Owned>3</Owned>
<Instancing>4</Instancing>
</CCC>
<CCC>
<Owned>3</Owned>
<Instancing>5</Instancing>
</CCC>
<CCC><Owned>4</Owned></CCC>
</bar>
<buzz>
<DDD><Owned>4</Owned></DDD>
<DDD><Owned>4</Owned></DDD>
<DDD><Owned>5</Owned></DDD>
<DDD><Owned>3</Owned></DDD>
<CCC><Owned>4</Owned></CCC>
</buzz>
</foo>
Is there a way to get the total value (SUM) of the latest value-of
call? And possibly remove all the foreach ?
The output with that should be 3 (2 + 1).