Jump to content
Changes to the Jaspersoft community edition download ×

Help on subreport and xPath


Recommended Posts

I have the following XML schema :


<shop shop1="Y" shop2="Y" shop3="N">
<field lable="a" value="1"/>
<field lable="b" value="2"/>
<field lable="A" value="11"/>
<field lable="B" value="22"/>
<field lable="aa" value="10"/>
<field lable="bb" value="20"/>
<field lable="AA" value="110"/>
<field lable="BB" value="220"/>
<field lable="aaa" value="100"/>
<field lable="bbb" value="200"/>
<field lable="AAA" value="111"/>
<field lable="BBB" value="222"/>


I have a master report and I would like to create just ONE subreport.

The tag <shop1>, <shop2>, and <shop3> have the same structure of descendant.


The master displays the number of subreport based on the values of the attributes

in the <shop> tag. If shop1 attr is 'Y', then display subreport shop1/section_1 and shop1/section_2.

Same with shop2, but not shop3 as the value of the attribute is 'N'.


My questions are :

1. how the master display the subreport based on the value shop/@shop1 ,shop/@shop2, and shop/@shop3 ?

I think this is within the scope of printwhenExpression.

If I define $F{shop1_field} as shop/@shop1, what'll be the printwhenExpression ?

Something like : $F{shop1_field} ? 'Y' : display_shop1

Similarly : $F{shop2_field} ? 'Y' : display_shop2 and $F{shop3_field} ? 'Y' : display_shop3


2. in the master report, what will be the subreportParameter, subreportParameterExpression,

subreportExpression, etc, if any ?


3. The subreport, either for shop1, shop2, or shop3 will display the rows like this :

$F{field1_label} : $F{field1_value} $F{field2_label} : $F{field2_value}

where $F{field1_label} is section_1/field/@label

$F{field1_value} is section_1/field/@value

$F{field2_label} is section_2/field/@label

$F{field2_value} is section_2/field/@value



The following code for subreport, of course, is incorrect :

<queryString language="xPath"><![CDATA[/shop/$F{parm_from_master}]]></queryString>

<field name="field1_label" class="java.lang.String">
<field name="field1_value" class="java.lang.String">
<field name="field2_label" class="java.lang.String">
<field name="field2_value" class="java.lang.String">

What will be the XPath and field descriptions ? I think the $F{parm_from_master} is related

with my question 1 or 2, is it ?


I really appreciate your help/suggestions.




Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • 2 weeks later...



I think you can get quicker help if you just go and read about xPath syntax. Don't wait for others to provide you with the correct xPath query for every report you need to create.

I'm not an xPath guy myself, so I won't attempt to answer your question, but I feel it would not be very difficult to master xPath in one or two days.


I hope this helps.


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