1

Topic: The total of substrings of tags

XSLT 1.0. Is XML.

<? xml version = "1.0" encoding = "windows-1251"?>
<Register>
<Line>
<C_CNT> 3 </C_CNT>
<C_NAZN> SUM: 0; INS_SUM: 0; SUM_1_1: 0; SUM_2_1:
0; SUM_3_1: 0; SUM_4_1: 0; SUM_5_1: 0; MONTH_2: .2017; SUM_1_2: 1; INS_SUM_1_2:
73.87; SUM_2_2: 0; SUM_3_2: 7; SUM_4_2: 0; SUM_5_2: 0; SUM_1_3: 0; SUM_2_3: 0; SUM_3_3:
0; SUM_4_3: 0; SUM_5_3: 0; SUM_1_4: 0; SUM_2_4: 0; SUM_3_4: 0; SUM_4_4: 0; SUM_5_4: 0;
MONTH_5: .2017; SUM_1_5: 1; INS_SUM_1_5: 0.00; SUM_2_5: 0; SUM_3_5: 0; SUM_4_5: 0;
SUM_5_5: 0; SUM_1_6: 0; SUM_2_6: 0; SUM_3_6: 0; SUM_4_6: 0; SUM_5_6: 0; CNT: 3; </C_NAZN>
</a line>
<Line>
<C_CNT> 2 </C_CNT>
<C_NAZN> SUM: 0; INS_SUM: 0; SUM_1_1: 0; SUM_2_1:
0; SUM_3_1: 0; SUM_4_1: 0; SUM_5_1: 0; MONTH_2: .2017; SUM_1_2: 3; SUM_2_2: 0;
SUM_3_2: 3; SUM_4_2: 0; SUM_5_2: 0; SUM_1_3: 0; SUM_2_3: 0; SUM_3_3: 0; SUM_4_3: 0;
SUM_5_3: 0; SUM_1_4: 0; SUM_2_4: 0; SUM_3_4: 0; SUM_4_4: 0; SUM_5_4: 0; MONTH_5:
.2017; SUM_1_5: 0; SUM_2_5: 0; SUM_3_5: 0; SUM_4_5: 0; SUM_5_5: 0; SUM_1_6: 0;
SUM_2_6: 0; SUM_3_6: 0; SUM_4_6: 0; SUM_5_6: 0; CNT: 2; </C_NAZN>
</a line>
<Line>
<C_CNT> 1 </C_CNT>
<C_NAZN> SUM: 2; INS_SUM: 0;
SUM_1_1: 0; SUM_2_1: 0; SUM_3_1: 0; SUM_4_1: 0; SUM_5_1: 0; SUM_1_2: 0; SUM_2_2: 0;
SUM_3_2: 0; SUM_4_2: 0; SUM_5_2: 0; SUM_1_3: 0; SUM_2_3: 0; SUM_3_3: 0; SUM_4_3: 0;
SUM_5_3: 0; SUM_1_4: 0; SUM_2_4: 0; SUM_3_4: 0; SUM_4_4: 0; SUM_5_4: 0; SUM_1_5: 0;
SUM_2_5: 0; SUM_3_5: 0; SUM_4_5: 0; SUM_5_5: 0; SUM_1_6: 0; SUM_2_6: 0; SUM_3_6: 0;
SUM_4_6: 0; SUM_5_6: 0; CNT: 1; </C_NAZN>
</a line>
</the register>

Wrote 2 template. template get_valid_registry_sum successfully considers the total on all , but get_valid_registry_sum2 what value is not nodeset. to count the total on elements CNT in tags C_NAZN swears?

<xsl:call-template name = "get_valid_registry_sum">
<xsl:with-param name = "element_name" select = "'C_CNT '"/>
</xsl:call-template>
<xsl:call-template name = "get_valid_registry_sum2">
<xsl:with-param name = "element_name" select = "'C_NAZN '"/>
<xsl:with-param name = "str_name" select = "'CNT '"/>
</xsl:call-template>
<xsl:template name = "get_valid_registry_sum">
<xsl:param name = "element_name"/>
<xsl:value-of select = "format-number ((sum (//the Line / * [name () = $element_name]) div 100) * 100, ' 0.00 ')"/>
</xsl:template>
<xsl:template name = "get_valid_registry_sum2">
<xsl:param name = "element_name"/>
<xsl:param name = "str_name"/>
<xsl:value-of select = "format-number (
(sum (
substring-before (
substring-after (//the Line / * [name () = $element_name]
,concat ($str_name, ': ')
)
,';'
)
) div 100
) * 100
, ' 0.00'
)"/>
</xsl:template>

2

Re: The total of substrings of tags

adar7;

<? xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<root>
<xsl:call-template name = "sum-nodes">
<xsl:with-param name = "nodes" select = "//Stroka/C_NAZN"/>
<xsl:with-param name = "str_name" select = "'CNT '"/>
</xsl:call-template>
</root>
</xsl:template>
<xsl:template name = "sum-nodes">
<xsl:param name = "nodes"/>
<xsl:param name = "str_name"/>
<xsl:param name = "sum" select = "0"/>
<xsl:param name = "newSum" select = "$ sum + number (substring-before (substring-after ($nodes [1], concat ($str_name, ': ')), '; '))"/>
<xsl:choose>
<xsl:when test = "count ($nodes)> 1">
<! - recursive call->
<xsl:call-template name = "sum-nodes">
<xsl:with-param name = "nodes" select = "$ nodes [position ()> 1]"/>
<xsl:with-param name = "str_name" select = "$ str_name"/>
<xsl:with-param name = "sum" select = "$ newSum"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select = "format-number ($newSum, ' 0 ')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>