Sub Reports with XML data

0

I'm unable to pass data from main report to subreport with XML as data. The approach I'm taking is have a MainReport with two sub reports in it SubReport1 and SubReport2. XPath for SubReport1 is /main-report/sub-report1/items/item similarly XPath for SubReport2 is /main-report/sub-report2/items/item. Below is sample xml

<main-report>
    <sub-report1>
        <header></header>
        <items>
            <item></item>
            <item></item>
            <item></item>
            <item></item>
            <item></item>
            <item></item>
            <item></item>
        </items>
        <footer></footer>        
    </sub-report1>
    <sub-report2>
        <header></header>
        <items>
            <item></item>
            <item></item>
            <item></item>
            <item></item>
            <item></item>
            <item></item>
            <item></item>
        </items>
        <footer></footer>        
    </sub-report2>
</main-report>

srins.9's picture
Joined: Aug 28 2015 - 8:11am
Last seen: 1 year 8 months ago

2 Answers:

0

Don't use absolute path starting from /main-report
Use relative path
https://community.jaspersoft.com/questions/524978/empty-subreport-xml-da...

sanbez's picture
832
Joined: Jan 11 2011 - 2:06am
Last seen: 6 days 6 hours ago
0

Finally, was able to solve problem. With above XML as Datasource.

Main Report

Step 1:  Have xPath as /main-report

    <queryString language="xPath">
        <![CDATA[/main-report]]>
    </queryString>

Step 2: Data Source Expression for sub report 1 

((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//main-report/sub-report1/line-items/line-item"

Step 3: Data Source Expression for Sub Report 2

((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//main-report/sub-report2/line-items/line-item")

Sub Report 1

<queryString language="xPath">
        <![CDATA[/main-report/sub-report1/line-items/line-item]]>
    </queryString>

Sub Report 2

    <queryString language="xPath">
        <![CDATA[/main-report/sub-report2/line-items/line-item]]>
    </queryString>

srins.9's picture
Joined: Aug 28 2015 - 8:11am
Last seen: 1 year 8 months ago
Feedback
randomness