itchytoes Posted April 22, 2010 Share Posted April 22, 2010 Hi --here is my sample simple XML data source:<AAA> <BBB bid ="1"> <CCC cid="10"/> <CCC cid="20"/> </BBB> <BBB bid="2"> <CCC cid="30"/> <CCC cid="40"/> </BBB></AAA>What I'm trying to do is write a report that groups by the BBB/@bid attributes, with the CCC/@cid attributes under each group.If I start my queryString with the /AAA/BBB xPath, I can set a <field> as ./@bid and I can group by this field and see my @bid values.However, I cannot seem to get a <detail> that will show the @cid fields under each group.When I try a <field> with //CCC/@cid as the xPath, all the details show the "10" value.When I try ./@cid as the xPath, all the details show just the first CCC/@cid under each BBB group. I don't see the 2nd BBB values.I thnik I can do a subreport and pass in the XML_DATA_DOCUMENT and start with a BBB where the @bid is equal to the current @bid I'm at as a parameter, but I have not tried that yet. I'd also like to avoid the subreport thing for this case.Is this sort of grouping possible?ThanksBetty Link to comment Share on other sites More sharing options...
therockita Posted April 25, 2010 Share Posted April 25, 2010 Hi Betty, The problem here is that a JasperReport using xml datasource can only work with one node set at a time. Take a look to this:http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/data/JRXmlDataSource.html Practically this means that you can not have "two iterations" in the same report (you have already an iteration for any BBB node). To resolve this inconvenient you just need to create a subreport, pass it the same document as datasource and change the initial XPath.You can use this code to achieve this (to be inserted into your Master report): Code:<subreport><reportElement positionType="Float" x="18" y="72" width="500" height="42"/> <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/AAA/BBB/CCC")]]></dataSourceExpression><subreportExpression class="java.lang.String"><![CDATA["path where the subreport is located"]]></subreportExpression></subreport> Link to comment Share on other sites More sharing options...
itchytoes Posted April 26, 2010 Author Share Posted April 26, 2010 Thanks for the reply. After trying a few more things, I gave up and wen the subreport route, and that does work. 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