xml - How to count the number of records/nodes in the xslt only whose value is greater than zero -


my xml below :

<report_entry>     <filedatetime>2016-01-05t22:45:55.692-08:00</ filedatetime>     < currentyear>2016</ currentyear>     < memnum>133034</ memnum>     < ssn>000000</ ssn>     < first_name>br</ first_name>     < last_name>g</ last_name>     < employee_status_date>2013-10-04-07:00</ employee_status_date>     < payrollresults>         < depodt>2016-01-08-08:00</ depodt>         < fsa_dep_contributions>48.08</ fsa_dep_contributions>         < fsa_limitd_contributions>0</ fsa_limitd_contributions>         < fsa_med_contributions>0</ fsa_med_contributions>     </ payrollresults> </ report_entry> < report_entry>     < filedatetime>2016-01-05t22:45:55.692-08:00</ filedatetime>     < currentyear>2016</ currentyear>     < memnum>205767</ memnum>     < ssn>777777</ ssn>     < first_name>r</ first_name>     < last_name>ks</ last_name>     < payrollresults>         < depodt>2016-01-08-08:00</ depodt>         < fsa_dep_contributions>0</ fsa_dep_contributions>         < fsa_limitd_contributions>0</ fsa_limitd_contributions>         < fsa_med_contributions>28.85</ fsa_med_contributions>     </ payrollresults> </ report_entry> 

xslt producing text file , counting number of rows in output file. file in output rows produced if of contribution greater 0 above xml. have used below code outputting 3 whereas should output 2. please let me know doing worng in code.

i using :

<xsl:variable name="recordcount">   <xsl:value-of select="      count( report_data/ report_entry/ payrollresults[last()]/ fsa_dep_contributions != 0) +     count( report_data/ report_entry/ payrollresults[last()]/ fsa_limitd_contributions != 0) +     count( report_data/ report_entry/ payrollresults[last()]/ fsa_med_contributions != 0)"/>  </xsl:variable> <xsl:value-of select="substring(concat($recordcount)"/> 

the reason original expressions didn't work because each expression returned boolean. count() of boolean 1.

you could've changed fsa_med_contributions != 0 fsa_med_contributions[. != 0]

you could've used starts-with(local-name(),'fsa') condense of count() calls 1.

also, instead of xsl:value-of, use select attribute when possible. eliminates need processor create new tree.

example:

<xsl:variable name="recordcount"    select="count(report_data/report_entry/payrollresults[last()]/*[starts-with(local-name(),'fsa') , . > 0])"/> 

note: there's no need escape > &gt; in xslt.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -