Search code examples
xpathjasper-reportssubreport

iReport sub-report with Xpath expression


This should be very easy, but my sub report report stays empty. my xml :

<?xml version="1.0" encoding="UTF-8"?>
<document>
    <settings></settings>
    <header></header>
    <lines>
        <line>
             <product_level>1</product_level>
            <product_description>description</product_description>
        </line>
         <line>
             <product_level>2</product_level>
            <product_description>description lvl2</product_description>
        </line>
         <line>
             <product_level>3</product_level>
            <product_description>description lvl3</product_description>
        </line>
    </lines>
</document>

my main document uses Xpath /document to select the data the sub report uses Xpath /document/lines/line to select the data

the problem starts with the subreport where I only want to select certain values, say where is 1 ( 1 )

using :

((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/document/lines/line/product_level[text()=3]")

results in a empty part.

If I leave out the /product_level[text()=3] it returns every line ( as expected )...

I am guessing it is something easy, but can't figure out what.


Solution

  • This is the correct XPath:

    /document/lines/line/product_level[text()='3']
    

    Here's a free tool to help in the future: http://www.bubasoft.net/product/xpath-builder/