Sorting in report with XML Datasource

0

Hi,

I have a report with XML as data source. The main report contains many List Components. I have to sort the data in the main report by adding a field in the Sorting Tab of Query Dialog. But when I do that I get the following error:

net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
Source text : ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/xyz/abc")
 
at com.jaspersoft.studio.editor.preview.view.control.ReportControler.fillReport(ReportControler.java:482)
 
at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$18(ReportControler.java:457)
 
at com.jaspersoft.studio.editor.preview.view.control.ReportControler$4.run(ReportControler.java:347)
 
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
 
Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
Source text : ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/xyz/abc")
 
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:244)
 
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)
 
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559)
 
at net.sf.jasperreports.components.list.FillDatasetRun.evaluate(FillDatasetRun.java:127)
 
at net.sf.jasperreports.components.list.BaseFillList.evaluate(BaseFillList.java:102)
 
at net.sf.jasperreports.engine.fill.JRFillComponentElement.evaluate(JRFillComponentElement.java:110)
 
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)
 
at net.sf.jasperreports.engine.fill.JRFillFrame.evaluate(JRFillFrame.java:149)
 
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)
 
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:456)
 
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2057)
 
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:778)
 
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:288)
 
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
 
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:932)
 
at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFiller.run(BaseFillHandle.java:120)
 
at java.lang.Thread.run(Unknown Source)
 
Caused by: java.lang.ClassCastException: net.sf.jasperreports.engine.fill.SortedDataSource cannot be cast to net.sf.jasperreports.engine.data.JRXmlDataSource
.
.
.
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:231)
 
... 16 more
 
I found the following work around in the community:
But when I tried to implement it, I get the following error:
 
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. JRXmlUtils cannot be resolved
                value = JRXmlUtils.createDocument(((java.lang.Object)field_node.getValue()), true); //$JR_EXPR_ID=29$
                        <-------->
2. JRXmlUtils cannot be resolved
                value = JRXmlUtils.createDocument(((java.lang.Object)field_node.getOldValue()), true); //$JR_EXPR_ID=29$
                        <-------->
3. JRXmlUtils cannot be resolved
                value = JRXmlUtils.createDocument(((java.lang.Object)field_node.getValue()), true); //$JR_EXPR_ID=29$
                        <-------->
3 errors
 
 
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:204)
 
at net.sf.jasperreports.eclipse.builder.JasperReportCompiler.compileReport(JasperReportCompiler.java:167)
 
at com.jaspersoft.studio.editor.preview.view.control.ReportControler.compileJasperDesign(ReportControler.java:405)
 
at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$14(ReportControler.java:396)
 
at com.jaspersoft.studio.editor.preview.view.control.ReportControler$4.run(ReportControler.java:329)
 
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

I would appreciate if anyone could help me with this issue.

Thanks in advance...

nagar.hemant's picture
Joined: May 23 2016 - 7:13am
Last seen: 2 years 2 months ago

1 Answer:

1

I think it was you'll have to use xslt to sort the xml document before passing it to JasperReports.

Following page on xslt may help you.

http://www.w3schools.com/xsl/el_sort.asp

hozawa's picture
52292
Joined: Apr 24 2010 - 4:31pm
Last seen: 5 months 4 days ago
Feedback
randomness