Hello, Being a newbie to the world of xml and xsl I am having difficulty creating a stylesheet to sum attribute values from my input xml.
The input xml has multiple Field nodes that each have a name attribute that I want to match to then get the value attribute and sum with all other occurances of that name attribute match throughout the input xml.
I can get the name attribute match to work but not the sum. The output I am getting is the value of each occurance rather than the sum. How do I get it to sum correctly do the output is just a summary of values?
Here is my input XML:
<RESPONSE>
<FEATURES>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="64.1"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="43.8"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="1141"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="72.56"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="45.2"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="1641"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="47.7"/>
<FIELD name="AVERAGE_AG" value="4.3"/>
<FIELD name="AVERAGE__1" value="41.3"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="1889"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="75.96"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="42"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="3191"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="72.56"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="45.2"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="3406"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="72.56"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="45.2"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="3424"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="64.1"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="43.8"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="3564"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="72.56"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="45.2"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="3696"/>
</FIELDS>
</FEATURE>
<FEATURECOUNT count="8" hasmore="false"/>
</FEATURES>
</RESPONSE>
Here is my XSL so far:
<?xml-stylesheet type="text/xsl" href="C:\jakarta-tomcat\webapps\sdsi\external\get_features_to_html.xsl"?>
<xsl:stylesheet version="1.0" xmlns:xsl=" <xslutput method="html"/>
<xslaram name="index" select="1"/>
<xsl:strip-space elements="*"/>
<xsl:template match="FIELD">
<xsl:if test="@name='WEIGHTED_L' ">Weighted LVR: <xsl:value-of select="sum(@value)"/>
<br/>
</xsl:if>
<xsl:if test="@name='AVERAGE_AG' ">Average Age: <xsl:value-of select="sum(@value)"/>
<br/>
</xsl:if>
<xsl:if test="@name='AVERAGE__1' ">Average Loan Age: <xsl:value-of select="sum(@value)"/> (years)<br/>
</xsl:if>
<xsl:if test="@name='_INVESTME' ">Investment: <xsl:value-of select="sum(@value)" />
<br/>
</xsl:if>
<xsl:if test="@name='_ARREARS_' ">Arrears: <xsl:value-of select="sum(@value)"/>
<br/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Thanks in advance for any assistance.
Dan
The input xml has multiple Field nodes that each have a name attribute that I want to match to then get the value attribute and sum with all other occurances of that name attribute match throughout the input xml.
I can get the name attribute match to work but not the sum. The output I am getting is the value of each occurance rather than the sum. How do I get it to sum correctly do the output is just a summary of values?
Here is my input XML:
<RESPONSE>
<FEATURES>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="64.1"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="43.8"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="1141"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="72.56"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="45.2"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="1641"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="47.7"/>
<FIELD name="AVERAGE_AG" value="4.3"/>
<FIELD name="AVERAGE__1" value="41.3"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="1889"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="75.96"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="42"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="3191"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="72.56"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="45.2"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="3406"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="72.56"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="45.2"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="3424"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="64.1"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="43.8"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="3564"/>
</FIELDS>
</FEATURE>
<FEATURE>
<FIELDS>
<FIELD name="WEIGHTED_L" value="72.56"/>
<FIELD name="AVERAGE_AG" value="0"/>
<FIELD name="AVERAGE__1" value="45.2"/>
<FIELD name="_INVESTME" value="0"/>
<FIELD name="_ARREARS_" value="0"/>
<FIELD name="#SHAPE#" value="[Geometry]"/>
<FIELD name="#ID#" value="3696"/>
</FIELDS>
</FEATURE>
<FEATURECOUNT count="8" hasmore="false"/>
</FEATURES>
</RESPONSE>
Here is my XSL so far:
<?xml-stylesheet type="text/xsl" href="C:\jakarta-tomcat\webapps\sdsi\external\get_features_to_html.xsl"?>
<xsl:stylesheet version="1.0" xmlns:xsl=" <xslutput method="html"/>
<xslaram name="index" select="1"/>
<xsl:strip-space elements="*"/>
<xsl:template match="FIELD">
<xsl:if test="@name='WEIGHTED_L' ">Weighted LVR: <xsl:value-of select="sum(@value)"/>
<br/>
</xsl:if>
<xsl:if test="@name='AVERAGE_AG' ">Average Age: <xsl:value-of select="sum(@value)"/>
<br/>
</xsl:if>
<xsl:if test="@name='AVERAGE__1' ">Average Loan Age: <xsl:value-of select="sum(@value)"/> (years)<br/>
</xsl:if>
<xsl:if test="@name='_INVESTME' ">Investment: <xsl:value-of select="sum(@value)" />
<br/>
</xsl:if>
<xsl:if test="@name='_ARREARS_' ">Arrears: <xsl:value-of select="sum(@value)"/>
<br/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Thanks in advance for any assistance.
Dan