Dataset filtering in a List

0

Hi,

I have following XML file and I am trying to display a parent and it's related children in the jasper report.

<family>
    <parent parentName="John">
        <children>
            <child childName="John Junior 1"/>
            <child childName="John Junior 2"/>
        </children>
    </parent>
    <parent parentName="Mike">
        <children>
            <child childName="Mike Junior 1"/>
            <child childName="Mike Junior 2"/>
            <child childName="Mike Junior 3"/>
        </children>
    </parent>
</family>

 

I am trying to create a report to show below:

John
    John Junior 1
    John Junior 2

Mike
    Mike Junior 1
    Mike Junior 2
    Mike Junior 3

 

But it is showing as below:

John
    John Junior 1
    John Junior 2
    Mike Junior 1
    Mike Junior 2
    Mike Junior 3

Mike
    John Junior 1
    John Junior 2
    Mike Junior 1
    Mike Junior 2
    Mike Junior 3

 

Can someone help?

thanks

 

paulk's picture
5
Joined: May 18 2012 - 12:32pm
Last seen: 1 year 7 months ago

4 Answers:

0

Just create a report with a group "parentName".

hozawa's picture
51278
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 months 1 week ago
0

Thank you for the suggestion.  I have already tried that and it still does not work.  I am trying to figure out how the dataset (XML) can have the <child>  node within the parent node.

Anyone have an example of JaspeReport Studio report file (with sample xml)?

thanks

 

 

paulk's picture
5
Joined: May 18 2012 - 12:32pm
Last seen: 1 year 7 months ago
1

Here you go. I just used a list with subdataset with $P{REPORT_DATA_SOURCE}) to list children names
 

 
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.1.final using JasperReports Library version 6.2.1 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="xmlDatasource" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="73f5cf4a-775e-4336-b2d5-fc024fb0de05">
<subDataset name="childNames" uuid="e6f15fd9-400d-4ae8-8640-050b4afabb7d">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="childNamesSample"/>
<queryString language="xPath">
<![CDATA[/family/parent/children/child]]>
</queryString>
<field name="childName" class="java.lang.String">
<fieldDescription><![CDATA[@childName]]></fieldDescription>
</field>
</subDataset>
<queryString language="xPath">
<![CDATA[/family/parent]]>
</queryString>
<field name="parentName" class="java.lang.String">
<fieldDescription><![CDATA[@parentName]]></fieldDescription>
</field>
<field name="childName" class="java.lang.String">
<fieldDescription><![CDATA[/children/child/@childName]]></fieldDescription>
</field>
<group name="parentName_1">
<groupExpression><![CDATA[$F{parentName}]]></groupExpression>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="20" y="24" width="100" height="30" uuid="1f021ee5-e0cb-45c7-ba8d-8303c3bca0ed"/>
<textFieldExpression><![CDATA[$F{parentName}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="80" y="60" width="200" height="30" uuid="32091ad3-76fd-4434-a7ef-4db5781e4fe6"/>
<datasetRun subDataset="childNames" uuid="e908046b-6e57-4519-ba65-ca1a17400576">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/parent/children/child")
]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="200">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="45c5cb36-3167-4973-8444-5b1f6ca996ed"/>
<textFieldExpression><![CDATA[$F{childName}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
hozawa's picture
51278
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 months 1 week ago
0

Thank you Hozawa,

it is working well.

paulk's picture
5
Joined: May 18 2012 - 12:32pm
Last seen: 1 year 7 months ago
Feedback
randomness