xml - Sum of number with XSL Transformation -
I want to calculate the balance of the customer's balance.
This is my XML code: define a key Then you can write This is a complete sample: When I run with Saxon 6.5.5 with my input sample then it will be
& lt; Bank & gt; & Lt; Accounts & gt; & Lt; Deposit Accounts & gt; & Lt; Deposit Account ID = "d1" interesse = "0.03" & gt; & Lt; Balance & gt; 2500 and lt; / Balance & gt; & Lt; / Deposit-account & gt; & Lt; Deposit Account ID = "d2" interesse = "0.03" & gt; & Lt; Balance & gt; 15,075 & lt; / Balance & gt; & Lt; / Deposit-account & gt; & Lt; / Deposit accounts & gt; & Lt; Bank accounts & gt; & Lt; Bank Account Id = "C1" & gt; & Lt; Balance & gt; 4025 & lt; / Balance & gt; & Lt; / Bank account & gt; & Lt; Bank Account Id = "C2" & gt; & Lt; Balance & gt; -125 & lt; / Balance & gt; & Lt; / Bank account & gt; & Lt; Bank-Account ID = "C3" & gt; & Lt; Balance & gt; 325 & lt; / Balance & gt; & Lt; / Bank account & gt; & Lt; / Bank accounts & gt; & Lt; / Accounts & gt; & Lt; Customers & gt; & Lt; Customers & gt; & Lt; Name & gt; Ben Richardson & lt; / Name & gt; & Lt; Address & gt; Park Drive 2 & lt; / Address & gt; & Lt; Accounts & gt; & Lt; Bank account riff = "c2" /> & Lt; Deposit account riff = "d1" /> & Lt; Bank account riff = "c1" /> & Lt; / Accounts & gt; & Lt; / Customer & gt; & Lt; / Customers & gt; & Lt; / Bank & gt;
and this is my xls code: & lt; Xsl: each selection = "customer" & gt;
& lt; Xsl: each selection = "accounts / *" & gt; & Lt; Xsl: variable name = "account" = "@ref" /> & Lt; Xsl: each selection = "/ bank / account / bank-account / bank-account" & gt; & Lt; Xsl: if test = "@ id = $ account" & gt; & Lt; Xsl: select value = "@ id" /> & Lt; Xsl: select value = "left" /> & Lt; / XSL: If & gt; & Lt; / XSL: for-each & gt; & Lt; Xsl: each selection = "/ bank / account / deposit account / deposit account" & gt; & Lt; Xsl: if test = "@ id = $ account" & gt; & Lt; Xsl: select value = "@ id" /> & Lt; Xsl: select value = "left" /> & Lt; / XSL: If & gt; & Lt; / XSL: for-each & gt; & Lt; / XSL: for-each & gt; & Lt; / Xsl: for-each & gt; Finally, I want to calculate the remaining customer's accounts of the remainder. In this case I want the result for the customer "Ben Riescharden" -125 + 4025 + 2500 = 6400. I try with the yoga function but the result -12540252500 (i.e. string of combinations) can you help me? Thanks a lot
& lt; Xsl: template match = "customer" & gt; & Lt; Xsl: Select value = "yoga (key ('ac', account / * / @ ref) / left)" /> & Lt; / XSL: Templates & gt;
& lt; Xsl: stylesheet xmlns: xsl = "http://www.w3.org/1999/XSL/conversion" version = "1.0" & gt; & Lt; Xsl: key name = "AC" match = "bank / account / deposit account / deposit account / bank / account / bank-account / bank-account" use = "@ id" /> & Lt; Xsl: template match = "/" & gt; & Lt; Xsl: Apply-Select Template = "// Client" /> & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "customer" & gt; Name: & lt; Xsl: Select the value = "name" />, sum: & lt; Xsl: Select value = "zodiac (key ('ac', account / * / @ ref / remainder)" />
name: Ben Richardson, Yoga: 6400
.
Comments
Post a Comment