2

I try to navigate through xml nodes in the reverse direction when I create a subreport but this is not working. My report XPath is /root/parent/child1 and I want a subreport to have /root/parent/child2 as XPath

<root>
  <parent>
    <child1>
    </child1>
    <child2>
    </child2>
  </parent>
</root>

I wrote the following in the data source expression:

((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//../child2")

My question is a general question about xpath:

Is it allowed to refer ancestors in the datasource expression with ".." or "../.."?

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Idrees Samim
  • 463
  • 5
  • 15

1 Answers1

1

The problem is that you are trying subDataSource

Creates a sub data source using the current node (record) as the root of the document

Hence your are creating a new document with a new root at child1 (XPath can't go beyond this new root)

Instead use dataSource

Creates a sub data source using as root document the document used by "this" data source.

In your example that would be:

((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/root/parent/child2")
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109