membersound Posted March 5, 2015 Share Posted March 5, 2015 How can I select a node from XML datasource by condition? Eg I have an xml that has multiple customer nodes. I now want to select the first customer whose type=business.Moreover, I want to sum up all values found fo the specific list elements.Example:<list> <customer> <type>business</type> <amount>10</amount> <!-- type String.class --> </customer> <customer> <type>private</type> <amount>20</amount> </customer></list>[/code]What is the jrxml expression for this? Do I have to use XPATH to locate the element? If yes, I could think of:/list/customer[type=business]/amount[/code]But how can I ensure that these values are summed up?And what if I just want to display these values repreatedly? How do I have to create the jrxml variables, fields and parameters to get automatically mapped from the xml?Same question applies if I have a java bean. Probably the mechanism/logic behind summing a field up automatically is the same?Thanks Link to comment Share on other sites More sharing options...
nuno-miguel-lourenco Posted March 23, 2015 Share Posted March 23, 2015 Hi,i've created an XML file with your content.Then created a new Data Adapter - XML Document, that points to the XML file with your content. Here what is important to note is to choose the option:Use the report Xpath expression when filling the reportAfterwards, at the Report's dataset expression just choose everything within the documentThen created a new Dataset and selected only the data needed (in this case all the "customer" data)With this new dataset i've added a table component to the report and assigned the newly created dataset to it. I've added a new Variable to the newly created dataset with the name Sum_Amount with the following expression: new java.math.BigDecimal($F{amount}), and the Calculation option as Sum.So, defined the dataset run of the table with the dataset as the next image shows. (Here I choose the Don't use any connection or Data Source option)So if we ran this:Cheers Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now