Jump to content
We've recently updated our Privacy Statement, available here ×

XML data source XPath and grouping


itchytoes

Recommended Posts

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?

Thanks

Betty

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

 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:
 
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...